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

Untyped functions content show up in mypy output #11155

Closed
rogalski opened this issue Sep 21, 2021 · 5 comments · Fixed by #11213
Closed

Untyped functions content show up in mypy output #11155

rogalski opened this issue Sep 21, 2021 · 5 comments · Fixed by #11213
Labels
bug mypy got something wrong

Comments

@rogalski
Copy link

rogalski commented Sep 21, 2021

Bug Report

For default configuration, violations can be reported in untyped (shouldn't be checked) functions.

To Reproduce

def f():
    return UNDEFINED


def g():
    return lambda x: UNDEFINED in x

https://mypy-play.net/?mypy=latest&python=3.10&gist=c49b86bc9067f234a038a71598d2b3b7

Expected Behavior

Both f() and g() are untyped - violations shouldn't be reported in any of those.

Actual Behavior

main.py:6: error: Name "UNDEFINED" is not defined

Your Environment

mypy-play, as linked above.

@rogalski rogalski added the bug mypy got something wrong label Sep 21, 2021
@sobolevn
Copy link
Member

sobolevn commented Sep 21, 2021

Good question!

We don't check unannotated functions without --check-untyped-defs option.
But, lambda is not considered to be unannotated, because it cannot be annotated due to Python syntax limitations.
So, lambda x: UNDEFINED in x is considered to be typed. That's why it is checked.

I also agree with its conclusion, UNDEFINED is not defined.
I guess I can update docs to mention this special case.

Related #10895 and #3948

@sobolevn
Copy link
Member

@hauntsaninja any ideas about the best place for such docs?

@sobolevn
Copy link
Member

I think that adding a new section here might be a good idea.

@sobolevn
Copy link
Member

Another option for lambda is to inherit "annotated" status from its context:

  • Not a function (module, class body) -> lambda is annotated
  • Annotated function / method -> lambda is annotated
  • Unannotated function / method -> lambda is not unnotated

@rogalski
Copy link
Author

+1 for inheriting annotated status from enclosing scope.

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.

2 participants