agronholm / agronholm/typeguard

NameError on Enum

オープン
#402 コメント 20 件 リアクション 0 件 担当者 0 名 GitHub で見る
bug
主要言語
Python
スター
1.8k
フォーク
145
平均マージ
8日 12時間
マージ済み PR(30日)
1

説明

### 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.10.12

### What happened?

```
Traceback (most recent call last):
File "test.py", line 3, in
from A import A
File "", line 1027, in _find_and_load
File "", line 1006, in _find_and_load_unlocked
File "", 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 "A.py", line 7, in
A()
File "A.py", line 5, in __init__
def __init__(self, e: E = E.X) -> None:
NameError: name 'E' is not defined. Did you mean: 'e'?
```

### How can we reproduce the bug?

`test.py`:
```python3

from typeguard import install_import_hook
with install_import_hook(('A',)):
import A
```
`A.py`:
```python3
from enum import Enum
class A:
class E(Enum):
X = 1
def __init__(self, e: E = E.X) -> None:
print("OK")
A()
```
```shell
$ python3 A.py
OK

$ python3 test.py

```

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。