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

By default, be picker about callable #546

Merged
merged 1 commit into from
Jan 15, 2025
Merged

By default, be picker about callable #546

merged 1 commit into from
Jan 15, 2025

Conversation

liamhuber
Copy link
Member

typeguard.check_type is quite relaxed when seeing if something is callable -- so much so that everything will pass through, even check_type(5, callable), or (as in the test suite) a check against an instance of a class that has not defined __call__. This switches the default behaviour of type_hinting.valid_value to convert raw callable hints into collections.abc.Callable, which check_type treats more rigorously. I believe this is closer to the intuitively expected behaviour of valid_value, but the original behaviour can still be recovered via a flag argument.

@XzzX, I only noticed this because of #545, so thanks for pushing that!

`typeguard.check_type` is quite relaxed when seeing if something is `callable` -- so much so that _everything_ will pass through, even `check_type(5, callable)`, or (as in the test suite) a check against an instance of a class that has not defined `__call__`. This switches the default to convert raw `callable` hints into `collections.abc.Callable`, which `check_type` treats more rigorously. I believe this is closer to the intuitively expected behaviour of `valid_value`, but the original behaviour can still be recovered via a flag argument.

Signed-off-by: liamhuber <[email protected]>
Copy link

Binder 👈 Launch a binder notebook on branch pyiron/pyiron_workflow/stricter_callable

@coveralls
Copy link

Pull Request Test Coverage Report for Build 12795803361

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage increased (+0.002%) to 91.48%

Files with Coverage Reduction New Missed Lines %
type_hinting.py 1 97.78%
Totals Coverage Status
Change from base Build 12795134771: 0.002%
Covered Lines: 3071
Relevant Lines: 3357

💛 - Coveralls

@liamhuber liamhuber merged commit a975dc7 into main Jan 15, 2025
19 checks passed
@liamhuber liamhuber deleted the stricter_callable branch January 15, 2025 20:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants