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

Add support for marking classes typing.final #1247

Open
Julian opened this issue Feb 25, 2024 · 3 comments
Open

Add support for marking classes typing.final #1247

Julian opened this issue Feb 25, 2024 · 3 comments
Labels
Typing Typing/stub/Mypy/PyRight related bugs.

Comments

@Julian
Copy link
Member

Julian commented Feb 25, 2024

I am filing the below not really having through details, though I at least don't see this mentioned in any other issue, hence splatting it out :). Spicy takes I'm sure coming below as I'm sure part of this rests on how much each of us tolerates inheritance.

Should attrs have a way to apply typing.final to its classes so that they're easier to mark as "don't subclass"? E.g. a final= argument to frozen / define / mutable?

Obviously stacking the two decorators works, so the motivation I guess for me personally is just "I always want final for basically any class I expose", so if attrs had this it's one less thing to forget. What I do now is usually things at runtime, which don't use final() at all, but given I just realized I should probably add final() too so that users who do rely on their type checkers see a warning, that made me wonder whether that half is something general enough to be here.

If it were an argument to define, defaulting to True obviously breaks backwards compatibility. Perhaps doing it for frozen at least is justifiable? Or at least desirable with a deprecation warning for subclassing in the interim?

Any thoughts on how reasonable that sounds?

@Julian
Copy link
Member Author

Julian commented Feb 25, 2024

OK I suppose I should have at least checked whether adding final() to things dynamically actually works, which a first try does not, at least with pyright. I haven't had coffee yet this morning so this all might be nonsense.

@hynek
Copy link
Member

hynek commented Feb 26, 2024

I think final and frozen are a bit different concepts, but the bigger question is if this is achievable with dataclass transforms at all?

@hynek hynek added the Typing Typing/stub/Mypy/PyRight related bugs. label Feb 26, 2024
@Julian
Copy link
Member Author

Julian commented Feb 27, 2024

Yeah sorry I forgot to come back to this after but it seemed like the answer was unfortunately "no".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Typing Typing/stub/Mypy/PyRight related bugs.
Projects
None yet
Development

No branches or pull requests

2 participants