stubgen creates duplicate class definitions
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 35/100
Hướng nghiên cứu
Bắt đầu với stubgen và cách nó xử lý các định nghĩa có điều kiện theo nền tảng trong serialposix; tệp được tạo stubs/serial/serialposix.pyi cho thấy các khai báo PlatformSpecific bị trùng lặp. Xác định cách biểu diễn các định nghĩa lớp dành riêng cho nền tảng, sau đó xác minh rằng stub được tạo không còn tạo ra các tên trùng lặp và mypy chấp nhận nó trên mọi nền tảng.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
I need a stub for the serial package, and attempted to use stubgen to create it. The problem arises in the serialposix subpackage, which defines the PlatformSpecific class differently depending upon the platform it's running on. When stubgen processes this code, it discards all the conditional pieces, the end result being multiple definitions of the PlatformSpecific class, which, not surprisingly, mypy is very unhappy about.
Here's what the original code looks like (trimmed for compactness):
plat = sys.platform.lower()
if plat[:5] == 'linux': # Linux (confirmed) # noqa
class PlatformSpecific(PlatformSpecificBase):
…
elif plat == 'cygwin': # cygwin/win32 (confirmed)
class PlatformSpecific(PlatformSpecificBase):
…
elif plat[:6] == 'darwin': # OS X
class PlatformSpecific(PlatformSpecificBase):
…
and so on. You get the picture.
Running mypy after generating the stub gives:
stubs/serial/serialposix.pyi:24: error: Name 'PlatformSpecific' already defined on line 20 stubs/serial/serialposix.pyi:29: error: Name 'PlatformSpecific' already defined on line 20 stubs/serial/serialposix.pyi:37: error: Name 'PlatformSpecific' already defined on line 20 stubs/serial/serialposix.pyi:42: error: Name 'PlatformSpecific' already defined on line 20
Now, I can manually go in and edit the generated stub, commenting out the class definitions for platforms other than the one I am running on. But the problem is that I can't then check in that stub and expect mypy to run correctly on other platforms.
I don't think this is a typeshed issue, because I don't see a way that the stub can be written to work across platforms, which seems to be a problem inherent in the way that stubgen, and stubs in general, work. Unless I'm missing something (which is entirely possible), there is nothing in mypy that will allow this type of code to be stubbed successfully.
- 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
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.
Issue khác của python/mypy
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
-
documentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
-
bug topic-configuration topic-error-reporting
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
qgis/QGIS-Documentation#11275 ·
-
bug priority:normal ready-for-dev
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
OpenHands/extensions#626 · 1 bình luận ·
-
Change observation tooltip text Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
CSCfi/sd-search-api#39 ·
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
-
please add to porn list Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
StevenBlack/hosts#3255 ·