Skip to content

Source code that has @final decorator does not require @final in stub #14921

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

Closed
sobolevn opened this issue Mar 18, 2023 · 0 comments · Fixed by #14922
Closed

Source code that has @final decorator does not require @final in stub #14921

sobolevn opened this issue Mar 18, 2023 · 0 comments · Fixed by #14922
Assignees
Labels
bug mypy got something wrong topic-stubtest

Comments

@sobolevn
Copy link
Member

Today I got hit by this. This was the source code:

from typing import final

@final
class A: ...

This was the stub:

class A: ...

But, stubtest allowed this.
I think that we should also check for __final__ attribute.

For example, some stdlib code already has @final decorators applied, like: https://github.com/python/cpython/blob/e1e9bab0061e8d4bd7b94ed455f3bb7bf8633ae7/Lib/asyncio/timeouts.py#L26

I will send a PR with the fix.

@sobolevn sobolevn added bug mypy got something wrong topic-stubtest labels Mar 18, 2023
@sobolevn sobolevn self-assigned this Mar 18, 2023
tyralla added a commit to tyralla/mypy that referenced this issue Mar 18, 2023
…thon#14921).

The special case of bound type variables was not handled in function `covers_at_runtime` of module `subtypes`.  So I added it and defined the test case `testNarrowSelfType`.
sobolevn added a commit that referenced this issue Mar 19, 2023
…14922)

Now, runtime code like

```python
from typing import final

@Final
class A: ...
``` 

Will require `@final` decorator in stubs as well.

Closes #14921
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-stubtest
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant