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

False negative: In a stub file @final must be applied only to the first overload #6866

Closed
hamdanal opened this issue Dec 31, 2023 · 2 comments
Labels
addressed in next version Issue is fixed and will appear in next published version bug Something isn't working

Comments

@hamdanal
Copy link

Describe the bug
pyright does not generate an error if @final appears on subsequent overloads. PEP 591 says:
"For overloaded methods, @final should be placed on the implementation (or on the first overload, for stubs)"

Code or Screenshots
Consider this pyi file:

from typing import final, overload

class C:
    @overload
    def f(self, x: int) -> int: ...
    @final
    @overload
    def f(self, x: str) -> str: ...
$ pyright t.pyi
0 errors, 0 warnings, 0 informations
$ mypy t.pyi
t.pyi:6: error: In a stub file @final must be applied only to the first overload  [misc]

VS Code extension or command-line
command-line: pyright 1.1.344

@hamdanal hamdanal added the bug Something isn't working label Dec 31, 2023
@erictraut
Copy link
Collaborator

The spec doesn't disallow @final from being applied to subsequent overloads, so I don't think that should be flagged as an error. However, I agree that pyright should report an error for cases where the first overload doesn't have a @final decorator but subsequent ones do.

I will also add this condition to the typing spec conformance tests that I've been working on.

erictraut added a commit that referenced this issue Jan 5, 2024
… function. Added missing check for override of an overloaded method marked `@final`. This addresses #6860 and #6866.
erictraut added a commit that referenced this issue Jan 5, 2024
… function. Added missing check for override of an overloaded method marked `@final`. This addresses #6860 and #6866. (#6918)
@erictraut erictraut added the addressed in next version Issue is fixed and will appear in next published version label Jan 5, 2024
@erictraut
Copy link
Collaborator

This is addressed in pyright 1.1.345, which I just published. It will also be included in a future release of pylance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addressed in next version Issue is fixed and will appear in next published version bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants