Skip to content

Assignment of type annotated variables inside @typechecked functions become None at runtime when using suppress_type_checks #380

@dodamih

Description

@dodamih

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

Python version

3.9 / 3.10 / 3.11

What happened?

When calling a @typechecked function within a suppress_type_checks context, any assignment of type annotated variables end up assigning None to the variable.

How can we reproduce the bug?

Run (from a file):

from typeguard import typechecked, suppress_type_checks

@typechecked
def foo():
    bar: int = 3
    print(bar)
    baz = 3
    print(baz)

with suppress_type_checks():
    foo()

Output:

None
3

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions