Skip to content

Members of a frozenset are not typechecked #367

@skeggse

Description

@skeggse

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.0.0

Python version

3.9.16

What happened?

>>> typeguard.check_type(frozenset({1}), frozenset[str])
frozenset({1}) # this should have raised a TypeCheckError

the behavior of set is as expected, however:

>>> typeguard.check_type(set({1}), set[str])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.9/site-packages/typeguard/_functions.py", line 105, in check_type
    check_type_internal(value, expected_type, memo)
  File "/usr/local/lib/python3.9/site-packages/typeguard/_checkers.py", line 756, in check_type_internal
    checker(value, origin_type, args, memo)
  File "/usr/local/lib/python3.9/site-packages/typeguard/_checkers.py", line 328, in check_set
    check_type_internal(v, args[0], memo)
  File "/usr/local/lib/python3.9/site-packages/typeguard/_checkers.py", line 761, in check_type_internal
    raise TypeCheckError(f"is not an instance of {qualified_name(origin_type)}")
typeguard.TypeCheckError: [1] of set is not an instance of str

This happens on v2, v3 and v4.

How can we reproduce the bug?

No third party libraries. Just import typeguard and run the above.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions