Strange custom type for `__init__` behaviour [@curry plugin]
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Python
- Star
- 20.6k
- Fork
- 3.3k
- Chỉ số merge pull request
- Chỉ số pull request đang chờ
Mô tả
- Are you reporting a bug, or opening a feature request?
Bug report / support question.
- Please insert below the code you are checking with mypy,
or a mock-up repro if the source is private. We would appreciate
if you try to simplify your case to a minimal repro.
I am working on @curry typed decorator support. https://github.com/dry-python/returns/pull/350
It works fine for all cases right now. Except for the case when __init__ method is curried.
In this particular case it changes our correct return type (returned from our custom plugin) to some strange incorrect type.
from returns.curry import curry
class Test(object):
@curry
def __init__(self, a: int, b: str) -> None:
...
@curry
def some(self, a: int, b: str) -> None:
...
t: Test
# Works fine!
reveal_type(t.some)
# => Revealed type is 'Overload(def () -> Overload(def (a: builtins.int, b: builtins.str), def (a: builtins.int) -> def (b: builtins.str)), def (a: builtins.int) -> def (b: builtins.str), def (a: builtins.int, b: builtins.str))'
# Modifies the return type from our plugin.
reveal_type(Test)
# => Revealed type is 'Overload(def () -> ex.Test, def (a: builtins.int) -> ex.Test, def (a: builtins.int, b: builtins.str) -> ex.Test)'
Full reproduction:
- Clone https://github.com/dry-python/returns/pull/350
poetry install- Drop the code from this issue into
./ex.py poetry run mypy ex.py
- What is the actual behavior/output?
Let's focus on the incorrect output we are getting for __init__ methods:
reveal_type(Test)
# => Revealed type is 'Overload(def () -> ex.Test, def (a: builtins.int) -> ex.Test, def (a: builtins.int, b: builtins.str) -> ex.Test)'
- What is the behavior/output you expect?
I expect it to have the exact same type our plugin produces:
Overload(def (self: ex.Test) -> Overload(def (a: builtins.int, b: builtins.str), def (a: builtins.int) -> def (b: builtins.str)), def (self: ex.Test, a: builtins.int) -> def (b: builtins.str), def (self: ex.Test, a: builtins.int, b: builtins.str))
The thing is this type is produced for both .some() and __init__ methods in this example. But, __init__ does change it for some reason. And .some() works correctly.
- What are the versions of mypy and Python you are using?
Do you see the same issue after installing mypy from Git master?
mypy:0.770- any
pythonfrom 3.6 to 3.8
- What are the mypy flags you are using? (For example --strict-optional)
Full list: https://github.com/dry-python/returns/blob/master/setup.cfg#L101
Useful links:
- Failing CI with the helpful error message: https://github.com/dry-python/returns/runs/666196191?check_suite_focus=true#step:7:660
- Failing typetest source: https://github.com/orsinium-forks/returns/blob/curry/typesafety/test_curry/test_curry/test_curry_arguments.yml#L20
- Implementation: https://github.com/orsinium-forks/returns/blob/curry/returns/curry.py#L38
- Plugin source: https://github.com/orsinium-forks/returns/blob/curry/returns/contrib/mypy/decorator_plugin.py#L116
- Upstream: https://github.com/dry-python/returns
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
Tái hiện vấn đề với pull request returns được liên kết: cài đặt nó bằng Poetry, lưu ví dụ dưới dạng ex.py và chạy poetry run mypy ex.py. Đọc returns/curry.py, returns/contrib/mypy/decorator_plugin.py và typetest curry được liên kết để so sánh __init__ với some. Hoàn thành khi kiểu Test giữ lại chữ ký curried do plugin tạo ra thay vì overload constructor không chính xác.
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
- compilers
- Loại issue
- Lỗi
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 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
- 35/100