Add typed attribute to third party class.
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 25/100
Direzione di ricerca
Inizia riproducendo i risultati di reveal_type in airflow/www/views.py:850 e il tentativo con TYPE_CHECKING intorno alla riga 115. Esamina come i tipi di Flask's flask.globals e stubgen gestiscono gli attributi di terze parti. Il lavoro sarà considerato completato quando l'issue avrà un approccio documentato e manutenibile oppure una funzionalità del type-checker chiaramente circoscritta per tipizzare tali attributi senza uno stub sostitutivo completo.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Feature
I would like to be able to add a (typed) attribute to a third-party class instance.
To give a specific example, Flask's current_app, and Flask-AppBuilder. Some example code:
def my_view(self):
reveal_type(current_app.appbuilder)
if current_app.appbuilder.sm.has_access(...):
...
The reveal_type here shows Any: airflow/www/views.py:850: note: Revealed type is 'Any'
Things I tried:
-
To add a typed attribute myself:
if TYPE_CHECKING: current_app.appbuilder = AppBuilder(None) reveal_type(current_app.appbuilder)Didn't work:
airflow/www/views.py:115: note: Revealed type is 'Any' -
A partial type stub file
I could use
stubgenetc to create a stub file for all offlaskand then edit the type inflask.globals, but this presents a maintenance burden that I don't want (keeping it in sync).I searched for any way I could to have a "partial" stub file -- if I could have a
stubs/flask/globals.pyiwith out neededing all the rest of the type stubs for this module, but couldn't get it working - likely not supported.
Pitch
I don't know what the feature would look like, but for the flask ecosystem it is fairly common to add properties on to the global flask object, or the g global variable, and I would love to be able to type-check my use of them, without needing to cast it at each use.
This issue is mostly a request for help/ "is there any sensible way of doing this?"
- 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
-
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 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
bancolombia/sentinel#23 ·
-
test md ApertaCI
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
langchain-ai/deepagents#6450 ·
-
bug client
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100