python / python/mypy

stubgen (stubgenc): Support for __new__ in C types

Aperta
#10,493 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

feature topic-stubgen
Lingua principale
Python
Stelle
20.6k
Fork
3.3k
Merge medio
1g 18h
PR unite (30g)
54

Descrizione

Feature

Implement support for __new__ in mypy.stubgenc.generate_c_type_stub

Pitch

Currently, there is a # TODO: We should support __new__. in mypy.stubgenc.generate_c_type_stub.
AFAIK, C extensions autogenerate the docstring Create and return a new object. See help(type) for accurate signature. for the __new__ / __init__ attributes of C type objects and I am not aware of a way to customize this.
Therefore, my proposal would be to use the docstring of the C type itself and scan for TypeName(...) (if TypeName is the name of the C type) and pass this to infer_sig_from_docstring.
Not sure if TypeName(...) should be required to include self / cls or if such an argument should be made optional (automatically add self to the signature of __init__ if it is missing in TypeName(...)).

I would offer to implement this, if we could specify the desired behavior.

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia da mypy.stubgenc.generate_c_type_stub e leggi come gestisce attualmente gli attributi dei tipi C e come chiama infer_sig_from_docstring. Chiarisci il parsing previsto e il comportamento di self/cls per TypeName(...) prima di implementarlo. Il lavoro è completato quando gli stub dei tipi C generati includono le firme concordate di new e init, derivate dalla docstring del tipo.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
tooling
Tipo di issue
Funzionalità
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
38/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.