agronholm / typeguard

Run-time type checker for Python
Other
1.51k stars 113 forks source link

Explicit 'comparison' with mypy #50

Open disconnect3d opened 5 years ago

disconnect3d commented 5 years ago

Hey,

It might be good to put a typeguard vs mypy in readme. I know those are different projects (runtime vs static) but that was my first question to a friend who linked it, so I guess other ppl might ask it too :P.

agronholm commented 5 years ago

What do I say besides the fact that typeguard works at run time and mypy is a static analyzer? I'm not sure I'm qualified to do an in-depth comparison.

disconnect3d commented 5 years ago

This should be a good starting point. It can be extended by an example where mypy can't find detect sth when typeguard can.

On Wed, Oct 17, 2018, 9:22 PM Alex Grönholm notifications@github.com wrote:

What do I say besides the fact that typeguard works at run time and mypy is a static analyzer? I'm not sure I'm qualified to do an in-depth comparison.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/agronholm/typeguard/issues/50#issuecomment-430756060, or mute the thread https://github.com/notifications/unsubscribe-auth/AJi7CkgVy3UdU7ZpLN5443tdlIcCb-kKks5ul4NugaJpZM4Xk_0j .

mixmastamyk commented 4 years ago

One other reason I tried and stuck with typeguard instead of mypy or pydantic is that it is 1/100th the size! From a cursory view it looks like this is a pure Python lib and the others need lots of stuff built with a compiler. I haven't looked deep to see if that is true however.

Great library by the way—I looked high and low for a function like check_type() and this is the first place I found it. ;-)

agronholm commented 4 years ago

Thanks. Typeguard has a long way to go though, and has a tiny fraction of the mindshare that the static checkers have.

mixmastamyk commented 4 years ago

Maybe a blurb in the docs could help. It can always grow in the future if needed.

oleks commented 2 years ago

Can it not make sense to use both typeguard and mypy?

agronholm commented 2 years ago

Yes, that is how the majority of the users (as I understand) use typeguard. Typeguard is an additional layer of safeguards.

oleks commented 2 years ago

Yes, that is how the majority of the users (as I understand) use typeguard. Typeguard is an additional layer of safeguards.

Cool, but then why do I get an error like this when trying to mypy code that uses typeguard:

error: Cannot find implementation or library stub for module named "typeguard"
note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
agronholm commented 2 years ago

Currently typeguard itself does not pass mypy checks (due to a number of workarounds) so it does not expose its type information to mypy, hence the error. This is something I want to solve, possibly in the next major release, if it's doable. In the meantime, I suggest you have mypy ignore these errors (a lot of libraries don't have type information available).

agronholm commented 1 year ago

As of v3.0.0, typeguard now passes mypy checks in strict mode. It also now contains py.typed, marking it as a typed library.