Feature request for something like --disallow-any-attrs
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
Disclaimer: mypy newbie here, so I might just be missing something. See also my StackOverflow question for my motivation to request this feature.
Basically I couldn't find a way for mypy to require type annotations on class attributes as in the following (incomplete) example with ignore_missing_imports turned on for sqlalchemy.*.
from sqlalchemy import Column, Integer
class Foo(Base):
oid = Column(Integer, primary_key=True)
I want code using my library (ORM definitions) to know what types they can expect. So I need mypy to make sure that oid is type annotated (e.g. oid: int = ...).
disallow_any_unimported does not seem to apply for oid. I also tried disallow_any_expr but this seems far to broad and has side-effects like causing mypy to complain about the use of Integer (Even with disallow_any_unimported = False).
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne damit, das gewünschte Verhalten für Klassenattribute anhand des bestehenden Verhaltens der Optionen disallow_any_unimported und disallow_any_expr zu vergleichen, wobei das SQLAlchemy Foo-Beispiel als motivierender Fall dient. Ermittle, wie eine separate Option die für disallow_any_expr beschriebenen umfassenderen Seiteneffekte vermeiden sollte, und überprüfe anschließend, dass annotierte und nicht annotierte Attribute die vorgesehenen Diagnosen erzeugen.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- compilers
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 25/100