Closed DanielYang59 closed 6 months ago
Thanks for the quick response @davidbrochart . You are legend and that is exactly what I was experiencing. However I tried the following which still didn't got an error for some reason?
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])
Do you have any advice? Thanks!
Seems like a bug.
Seems like a bug.
No, it's not. check_type()
does not use the global configuration. You need to pass the collection_check_strategy=CollectionCheckStrategy.ALL_ITEMS
as keyword argument to the function.
This default was adopted because Beartype adopted it, but given how many complaints I've received because of it, typically from users who post bug reports without reading the documentation first, I'm seriously considering reverting this behavior in the next major release.
typically from users who post bug reports without reading the documentation first
Apologies, I have been one of them 😠. Yes could confirm this works as expected.
from typeguard import check_type, CollectionCheckStrategy
check_type(
value=[1, "hi"], expected_type=list[int, int],
collection_check_strategy=CollectionCheckStrategy.ALL_ITEMS
)
Things to check first
[X] I have searched the existing issues and didn't find my bug already reported there
[X] I have checked that my bug is still present in the latest release
Typeguard version
4.1.5
Python version
3.11.7
What happened?
First time
typeguard
user and hope I'm not asking a silly question here. But the following code doesn't seem to trigger an error for some reason:Maybe I missed something? Thanks.
How can we reproduce the bug?