-
Notifications
You must be signed in to change notification settings - Fork 115
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
Type checking on generic only checks first value entry in data structure #418
Comments
This isn't a bug. Typeguard and Beartype both only check the first element of each collection by default, as checking every element would significantly slow down the application. This can be configured by setting Where should I document this so people wouldn't send bug reports about this all the time (see #417 for the last one)? |
Sorry @agronholm, I seems to have sent another issue regarding this behaviour in #439. But for some reason the following doesn't trigger an error: import typeguard
from typeguard import check_type, CollectionCheckStrategy
typeguard.config.collection_check_strategy = CollectionCheckStrategy.ALL_ITEMS
check_type(value=[1, "hi"], expected_type=list[int]) Update: should use the following: from typeguard import check_type, CollectionCheckStrategy
check_type(
value=[1, "hi"], expected_type=list[int, int],
collection_check_strategy=CollectionCheckStrategy.ALL_ITEMS
) |
Closing due to not a bug. I'll think about reverting the default setting in the next major release. |
Things to check first
I have searched the existing issues and didn't find my bug already reported there
I have checked that my bug is still present in the latest release
Typeguard version
4.1.5
Python version
3.10
What happened?
The function
check_type(value=value, expected_type=expected_type)
only checks the first entry of a Dict / List etc.How can we reproduce the bug?
Reproduce with (pseudo-code)
check_type(value={'a': 1, 1: 1}, expected_type=Dict[str, int])
confirms correct type but it is not true for the second entry in the dict.Same issue for
Dict[str, Dict[str, int]]
List[Dict[int, int]]
The text was updated successfully, but these errors were encountered: