Unions with invalid arguments are still allowed

Đang mở
#3,258 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
45/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
python
Lĩnh vực
devtools

Hướng nghiên cứu

Reproduce the issue with the shown Union[123] example and trace how mypy validates Union arguments. Add a regression test showing that the invalid argument is rejected, then run the relevant type-checker tests and confirm valid Union arguments still pass.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

bug topic-runtime-semantics
from typing import Union
Union[123]

Doesn't give any errors, but fails at runtime:

Traceback (most recent call last):
  File "tst.py", line 2, in <module>
    Union[123]
  File "/media/ryan/stuff/anaconda/lib/python3.6/typing.py", line 626, in inner
    return func(*args, **kwds)
  File "/media/ryan/stuff/anaconda/lib/python3.6/typing.py", line 744, in __getitem__
    parameters = tuple(_type_check(p, msg) for p in parameters)
  File "/media/ryan/stuff/anaconda/lib/python3.6/typing.py", line 744, in <genexpr>
    parameters = tuple(_type_check(p, msg) for p in parameters)
  File "/media/ryan/stuff/anaconda/lib/python3.6/typing.py", line 356, in _type_check
    raise TypeError(msg + " Got %.100r." % (arg,))
TypeError: Union[arg, ...]: each arg must be a type. Got 123.
Ngôn ngữ chính
Python
Star
20.6k
Fork
3.3k
Merge trung bình
1 ngày 18 giờ
Pull request đã merge (30 ngày)
54

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của python/mypy

Tất cả issue của python/mypy

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.