typeguard icon indicating copy to clipboard operation
typeguard copied to clipboard

Type checking for dataclasses

Open jsh9 opened this issue 4 years ago • 9 comments

Hi, I'm wondering if there can be support for type checking dataclasses? Currently, when I put @typeguard.typechecked on top of a dataclass definition, no checking happens (unless I'm mistaken).

Thanks!

jsh9 avatar Oct 25 '20 23:10 jsh9

Here's what I'm doing for this case:

https://gist.github.com/svermeulen/8a6ad727113a6d07f78332152c1d33b2

svermeulen avatar Dec 23 '20 03:12 svermeulen

@svermeulen Your gist works! Want to PR this to this project? Can I PR it? It needs a license.

dblock avatar Sep 15 '21 13:09 dblock

Feel free to PR it. I've added MIT license now

svermeulen avatar Sep 15 '21 13:09 svermeulen

Did this get merged?

idvorkin avatar Feb 11 '23 16:02 idvorkin

No, and I'm not sure what approach I want to take with regards to checking class/instance variable assignments. I don't think I will add support in v3.0. Maybe in a later release.

agronholm avatar Feb 11 '23 18:02 agronholm

That's a shame. With typeguard 2 this used to work if I am not mistaken.

faph avatar Mar 23 '23 16:03 faph

It never did work with typeguard 2.

agronholm avatar Apr 08 '23 21:04 agronholm

Hi @agronholm - are you planning to support this in typeguard 4?

dkamm avatar Apr 26 '23 06:04 dkamm

Maybe in some follow-up minor release, but not the 4.0 release that is imminent.

agronholm avatar Apr 26 '23 07:04 agronholm

In the case when one doesn't know what approach use to a solution like this, the best is to be flexible and give a temporary solution that works for the simpler and most fundamental case, that we know most devs would use, than to not give an alternative at all. I'm sure most of use are doing almost the same. What is the issue with the proposed solution?, why not just split the logic for class, and instances, and weirder cases?

NicolasNarvaez avatar Sep 30 '24 00:09 NicolasNarvaez