Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get back check_argument_types and check_return_type #437

Open
1 task done
albertz opened this issue Feb 14, 2024 · 3 comments
Open
1 task done

Get back check_argument_types and check_return_type #437

albertz opened this issue Feb 14, 2024 · 3 comments

Comments

@albertz
Copy link

albertz commented Feb 14, 2024

Things to check first

  • I have searched the existing issues and didn't find my feature already requested there

Feature description

Bring back check_argument_types and check_return_type.

There is quite a lot of code out there which uses check_argument_types and check_return_type and where authors do not want to update because they prefer the old API, or it's just too much effort to rewrite.
PaddlePaddle/PaddleSpeech#3056
espnet/espnet#5009
ExaWorks/psij-python#363

Also, one could argue, check_argument_types was simpler to use, it did not require a decorator. There could be reasons why you want to avoid using a decorator.

(I'm not sure if this feature request makes sense. I just want to raise awareness of the fact that a number of projects stick to old typeguard versions because of this. This is causing problems now for me because I want to use some of those projects (ESPnet) together with some own code which uses a new typeguard version, and this does not work now because of the incompatibility.)

Use case

Be able to update to newest version.

@agronholm
Copy link
Owner

I never intended for these to be used by library authors. My goal was always to provide noninvasive type checks, but it took me a long while to figure out how to do that. But now it sounds like the cat is out of the bag, and library authors have started using these checks that I threw away. I'll need to think about it, but progress has been slow as I haven't been maintaining this project very actively as of late.

@agronholm
Copy link
Owner

Wait, these projects are pinning typeguard to v2.13, not even 4.0? Can you elaborate on why you would want to avoid the decorator?

@albertz
Copy link
Author

albertz commented Mar 24, 2024

I think v2.13 was the last version with check_argument_types and check_return_type?

I'm not affiliated with those projects, so I can only tell for myself why I don't like decorators:

  • They can modify the behavior of the method/function in a way that I don't see at the same place. They can have side effects that I don't see. I like to do things more explicit. (That's a big reason for me.)
  • Static type checkers, IDEs (e.g. PyCharm) etc usually get confused about the types, don't support auto-completion and/or type checks properly anymore. (Also a big reason. I like my auto-complete and warnings by the IDE when I do sth wrong.)
  • Decorators might break some code in various ways, e.g. when combined with other decorators, or when there is other code inspecting the method attributes, or maybe in combination with metaclasses, staticmethods, classmethods, etc. Some of those bugs are also not easily detected directly. You cannot be sure that by introducing decorators to some method, that everything will behave 100% the same as before. (Otherwise I would just make those edits to those projects and corresponding PRs. But I don't because I'm not sure if it might break something.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants