Strange custom type for `__init__` behaviour [@curry plugin]
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 35/100
Rechercherichtung
Reproduziere das Problem mit dem verlinkten returns-Pull-Request: Installiere ihn mit Poetry, speichere das Beispiel als ex.py und führe poetry run mypy ex.py aus. Lies returns/curry.py, returns/contrib/mypy/decorator_plugin.py und den verlinkten curry-Typetest, um __init__ mit some zu vergleichen. Als abgeschlossen gilt die Aufgabe, wenn der Typ Test die vom Plugin erzeugte curry-Signatur beibehält, anstatt die falsche Konstruktorüberladung zu verwenden.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
- 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
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- Ø Merge
- 1 T. 18 Std.
- Gemergte PRs (30 T.)
- 54
Beitragsleitfaden
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus python/mypy
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
-
documentation
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
-
bug topic-configuration topic-error-reporting
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
Ähnliche Issues
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 86/100
zostera/django-bootstrap4#894 ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
use-agent-os/agent-os#3276 ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 88/100
zephyrproject-rtos/zephyr#119726 ·
-
area/auth bug comp/agent P3 platform/discord type/security
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 88/100
NousResearch/hermes-agent#117848 ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
zilliztech/memsearch#759 ·