Strange custom type for `__init__` behaviour [@curry plugin]
还没有人认领这个 Issue。
评估
调研方向
使用链接的 returns pull request 重现该问题:使用 Poetry 安装它,将示例保存为 ex.py,然后运行 poetry run mypy ex.py。阅读 returns/curry.py、returns/contrib/mypy/decorator_plugin.py 以及链接的 curry typetest,以比较 __init__ 和 some。完成标准是 Test 类型保留 plugin 生成的 curried 签名,而不是错误的构造函数重载。
由索引模型根据 Issue 内容生成。
描述
- 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
- 主要语言
- Python
- 星标
- 20.6k
- 派生
- 3.3k
- 平均合并
- 1 天 18 小时
- 30 天内合并 PR
- 54
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
python/mypy 的其他 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 75/100
-
bug
难度 2/5 1-3 小时 新手友好度 78/100
-
bug
难度 2/5 1-3 小时 新手友好度 76/100
-
documentation
难度 2/5 1-3 小时 新手友好度 72/100
-
bug topic-configuration topic-error-reporting
难度 2/5 1-3 小时 新手友好度 68/100
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 65/100
qgis/QGIS-Documentation#11275 ·
-
bug priority:normal ready-for-dev
难度 2/5 1-3 小时 新手友好度 88/100
OpenHands/extensions#626 · 1 条评论 ·
-
难度 1/5 1 小时以内 新手友好度 90/100
CSCfi/sd-search-api#39 ·
-
难度 1/5 1 小时以内 新手友好度 90/100
-
难度 2/5 1-3 小时 新手友好度 68/100
StevenBlack/hosts#3255 ·