Infer attributes from __new__
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 30/100
Direzione di ricerca
Start by reading mypy's semantic-analysis handling of new and assignments to the object created by object.new. Trace how super(...) calls are handled, then verify that attributes assigned through the created object are recognized on instances such as x.foo, including in unannotated methods.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
In this example (from #982) we define an attribute via assignment in __new__:
class C(object):
def __new__(cls, foo=None):
obj = object.__new__(cls)
obj.foo = foo
return obj
x = C(foo=12)
print(x.foo)
Currently mypy doesn't recognize attribute foo and complains about x.foo. To implement this, we could do these things:
- Infer the fact that
objis something similar toselfbecause of the way is created viaobject.__new__. This should happen during semantic analysis so that this will work in unannotated method as well. - Infer attributes from assignments via
objbecause it is classified as similar toself. - Also recognize
object.__new__calls viasuper(...).
- Lingua principale
- Python
- Stelle
- 20.6k
- Fork
- 3.3k
- Merge medio
- 1g 18h
- PR unite (30g)
- 54
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di python/mypy
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
-
documentation
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
-
bug topic-configuration topic-error-reporting
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
Issue simili
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
zostera/django-bootstrap4#894 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
use-agent-os/agent-os#3276 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
zephyrproject-rtos/zephyr#119726 ·
-
area/auth bug comp/agent P3 platform/discord type/security
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
NousResearch/hermes-agent#117848 ·