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

Conditional decorated functions are not type checked #17211

Open
davidhalter opened this issue May 3, 2024 · 0 comments
Open

Conditional decorated functions are not type checked #17211

davidhalter opened this issue May 3, 2024 · 0 comments
Labels
bug mypy got something wrong

Comments

@davidhalter
Copy link

davidhalter commented May 3, 2024

Bug Report

Going through Mypy's tests, I realized that some tests are passing that shouldn't. This involves for example:

  • testConditionalFunctionDefinitionUsingDecorator3 (there's an error in the test that the test author probably didn't notice: Positional only args of a callable are never assignable to a normal function with positional-or-keyword params; typically an error in Mypy would look like this: Incompatible redefinition (redefinition with type "Callable[[int], None]", original type "Callable[[Arg(int, 'x')], None]"))
  • testConditionalFunctionDefinitionUsingDecorator4 (there's even a TODO in there that complains about this not being done)
  • testNewAnalyzerConditionalDecoratedFunc

To Reproduce

from typing import Callable
def dec(f) -> Callable[[int], None]: raise NotImplementedError

if int():
    def f(x: str): pass
else:
    @dec
    def f() -> None: pass   

https://mypy-play.net/?mypy=latest&python=3.12&gist=18b131da809d740eced20dd7652ea213

Expected Behavior

It would be nice if Mypy complained here (like in AFAIK all other conditional definitions).

I'm happy to assist if somebody wants to fix this.

@davidhalter davidhalter added the bug mypy got something wrong label May 3, 2024
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

No branches or pull requests

1 participant