inspect.signature crashes with NameError for TYPE_CHECKING-only annotations
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Python
- Star
- 77.2k
- Fork
- 35.9k
- Chỉ số merge pull request
- Chỉ số pull request đang chờ
Mô tả
Bug report
Bug description:
if typing.TYPE_CHECKING:
from somelib import SomeType
def f(arg: SomeType): ...
inspect.signature(f) # NameError: name 'SomeType' is not defined
Some linters have rules that move imports into TYPE_CHECKING blocks and after this seemingly benign change inspect.signature will unexpectedly fail, even if its caller never cared about annotations.
At the very least, the documentation of inspect.signature should warn about this (currently it only talks about string annotations and makes no mention of Python 3.14 lazy annotations). But perhaps there’s a way of making inspect.signature work without such a surprising behavior, maybe by making some Signature fields lazy.
CPython versions tested on:
3.14
Operating systems tested on:
Linux
Linked PRs
- gh-153055
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu với entry point inspect.signature và hành vi lazy-annotation của Python 3.14 được mô tả trong báo cáo. Xem xét PR gh-153055 được liên kết trước khi xác định phạm vi được chấp nhận là tài liệu hay thay đổi hành vi; issue không xác định một điều kiện hoàn thành duy nhất.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- python
- Lĩnh vực
- backend
- Loại issue
- Lỗi
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Cần làm rõ
- Mức phù hợp với người mới
- 25/100