Skip to content

Weird problem with IntEnum #398

@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.1.3

Python version

3.10.12

What happened?

Traceback (most recent call last):
  File "test.py", line 4, in <module>
    import_module('A')
  File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "/home/jolaf/.local/lib/python3.10/site-packages/typeguard/_importhook.py", line 98, in exec_module
    super().exec_module(module)
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "A.py", line 2, in <module>
    class A(IntEnum):
  File "/usr/lib/python3.10/enum.py", line 289, in __new__
    enum_member = __new__(enum_class, *args)
  File "A.py", line 3, in __new__
    def __new__(cls, value: int, phrase: str = "") -> "A":
NameError: name 'A' is not defined

How can we reproduce the bug?

test.py:

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

A.py:

from enum import IntEnum
class A(IntEnum):
    def __new__(cls, value: int, phrase: str = "") -> "A":
        obj = int.__new__(cls, value)
        obj._value_ = value
        obj.phrase = phrase
        return obj
    v = 5
$ python3 test.py

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions