`tarfile.TarFile` has several missing overloads
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Python
- Star
- 5.1k
- Fork
- 2.1k
- Merge trung bình
- 1 ngày 19 giờ
- Pull request đã merge (30 ngày)
- 82
Mô tả
Right now TarFile.__init__ is defined as: https://github.com/python/typeshed/blob/c7e29eccd9759411c0f46580e20727038668b320/stdlib/tarfile.pyi#L128-L132
Which is not exactly right, because there's a case when name and fileobj are both None at the same time. And this will lead to runtime errors:
>>> import tarfile
>>> tarfile.TarFile(None, fileobj=None)
Traceback (most recent call last):
File "<python-input-2>", line 1, in <module>
tarfile.TarFile(None, fileobj=None)
~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^
File "/Users/sobolev/Desktop/cpython/Lib/tarfile.py", line 1729, in __init__
fileobj = bltn_open(name, self._mode)
TypeError: expected str, bytes or os.PathLike object, not NoneType
Right now mypy does not raise any errors for this broken case: https://mypy-play.net/?mypy=latest&python=3.12&gist=7452d274249fafba1f8a16565d5486c6
We need either name or fileobj, they can be both None at the same time. So, we need to add overloads.
There are several other methods that needs to be updated like open and taropen, maybe others.
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 stdlib/tarfile.pyi quanh các dòng 128-132 và xem lại các chữ ký của TarFile.init, open và taropen. Tái hiện lệnh gọi None/None bằng mypy, sử dụng ví dụ playground được liên kết, sau đó kiểm tra rằng các overload biểu diễn các tổ hợp name/fileobj hợp lệ và chẩn đoán trường hợp không hợp lệ.
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
- devtools
- Loại issue
- Lỗi
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 48/100