[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.5
What happened?
When using the @typechecked decorator to assure that a function accepts a list of strings as input (e.g. input_a : list[str]) a typeguard.TypeCheckError is raised only when the first element of the list does not match the requested type.
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.5
What happened?
When using the @typechecked decorator to assure that a function accepts a list of strings as input (e.g. input_a : list[str]) a typeguard.TypeCheckError is raised only when the first element of the list does not match the requested type.
Example: from typeguard import typechecked
@typechecked def run(input_sequence_list: list[str]) -> None: print(input_sequence_list)
run(input_sequence_list=[1, 2, 3, 22])
Output: typeguard.TypeCheckError: item 0 of argument "input_sequence_list" (list) is not an instance of str
The following example does not raise an error:
from typeguard import typechecked
@typechecked def run(input_sequence_list: list[str]) -> None: print(input_sequence_list)
run(input_sequence_list=["1", 2, 3, 22])
Output: ['1', 2, 3, 22]
Is this intended behaviour?
How can we reproduce the bug?
Install python 3.11.5 pip install typeguard==4.1.5
run the code below.
from typeguard import typechecked @typechecked def run(input_sequence_list: list[str]) -> None: print(input_sequence_list)
run(input_sequence_list=["1", 2, 3, 22])