Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request for something like --disallow-any-attrs #8670

Open
3rdcycle opened this issue Apr 14, 2020 · 1 comment
Open

Feature request for something like --disallow-any-attrs #8670

3rdcycle opened this issue Apr 14, 2020 · 1 comment
Labels

Comments

@3rdcycle
Copy link

3rdcycle commented Apr 14, 2020

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).

@ezyang
Copy link

ezyang commented Jan 28, 2024

I would find this useful too! I wouldn't mind if the expression was explicitly annotated as Any, I just want to force people to think about assigning types to all instance variables on a class.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants