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

PEP 647: Error if overriding typeguard with non-typeguard in subclass #9928

Closed
gvanrossum opened this issue Jan 18, 2021 · 2 comments · Fixed by #10300
Closed

PEP 647: Error if overriding typeguard with non-typeguard in subclass #9928

gvanrossum opened this issue Jan 18, 2021 · 2 comments · Fixed by #10300
Labels
bug mypy got something wrong

Comments

@gvanrossum
Copy link
Member

gvanrossum commented Jan 18, 2021

See #9865. (UPDATED)

I believe we should issue an error in this case.

See (disabled) test:

[case testTypeGuardMethodOverride-skip]
from typing_extensions import TypeGuard
class C:
def is_float(self, a: object) -> TypeGuard[float]: pass
class D(C):
def is_float(self, a: object) -> bool: pass # E: Some error
[builtins fixtures/tuple.pyi]

@gvanrossum gvanrossum added the bug mypy got something wrong label Jan 18, 2021
@sudojarvis
Copy link

i am newbie here. I want to resolve this issue. Please provide me hints.

@freundTech
Copy link
Contributor

freundTech commented Jan 18, 2021

@sudojarvis PEP 647 (https://www.python.org/dev/peps/pep-0647/) adds typeguards to python.
Support for typeguards has just been added to mypy in #9865. Looking at what that PR changed would be a good start.

You probably also want to check out TypeChecker.check_method_or_accessor_override_for_base()

mypy/mypy/checker.py

Lines 1424 to 1427 in fffbe88

def check_method_or_accessor_override_for_base(self, defn: Union[FuncDef,
OverloadedFuncDef,
Decorator],
base: TypeInfo) -> bool:

JukkaL pushed a commit that referenced this issue Apr 12, 2021
…ss (#10300)

Closes #9928.

Issue an error about incompatible signature when trying to override typeguard method 
with non-typeguard one.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants