Skip to content

Problem with := operator #510

@jolaf

Description

@jolaf

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

Python version

3.12.1

What happened?

Traceback (most recent call last):
  File "test.py", line 3, in <module>
    import A
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/typeguard/_importhook.py", line 98, in exec_module
    super().exec_module(module)
  File "A.py", line 7, in <module>
    f()
  File "A.py", line 3, in f
    if v := tuple():
       ^^^^^^^^^^^^
TypeError: check_variable_assignment() takes 3 positional arguments but 4 were given

How can we reproduce the bug?

test.py:

from typeguard import install_import_hook
with install_import_hook(('A',)):
    import A

A.py:

def f() -> None:
    v: str
    if v := tuple():
        pass
    print("OK")

f()
$ python3 A.py
OK

$ python3 test.py
<crash>

The problem only occurs when v is a local variable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions