10000 Mypy ignores typing.no_type_check for nested function redefintions. · Issue #10002 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

Mypy ignores typing.no_type_check for nested function redefintions. #10002

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

Open
bharel opened this issue Feb 1, 2021 · 3 comments
Open

Mypy ignores typing.no_type_check for nested function redefintions. #10002

bharel opened this issue Feb 1, 2021 · 3 comments
Labels
bug mypy got something wrong topic-pep-484

Comments

@bharel
Copy link
bharel commented Feb 1, 2021

Bug Report

Mypy ignores no_type_check, specifically for nested function redefinitions.

image

To Reproduce

  1. Create a nested function.
  2. Create another nested function in the same name right after it.
  3. Attempt to suppress it with @typing.no_type_check.

I've tried to deal with it in many ways, including opening a different bug, to no avail.

Your Environment

  • Mypy version used: 0.800
  • Mypy command-line flags: --disallow-untyped-defs, --show-column-numbers, --follow-imports=silent, --ignore-missing-imports, --check-untyped-defs
  • Mypy configuration options from mypy.ini (and other config files): Nope
  • Python version used: 3.9.0
  • Operating system and version: Windows 10
@bharel bharel added the bug mypy got something wrong label Feb 1, 2021
@terencehonles
Copy link
Contributor

I would expect the decorator applies to the body not to the name itself. For that I would expect you would still need # type: ignore[no-redef] but it looks like you also have the decorator on the enclosing function so I would expect you not to need the type comment.

For kicks do you want to test if the name test is the only issue or does it not descend into enclosed functions? Actually looking at #10001 you are suggesting it is type checking the enclosed function.

I would expect you would need

@no_type_check
def wrapper(...):
    # lines don't need type: ignore

    @no_type_check
    def wrapped(...):  # type: ignore[no-redef]
        # lines don't need type: ignore

If you indeed need the # type: ignore[no-redef] on the enclosed function I would suggest that's a bug since it should be covered by the @no_type_check decorator on wrapper, but I'm not sure mypy should default to not type checking recursively. If you are incrementally adding types you may add typing to the enclosed function and it might be better to be explicit and add the @no_type_check decorator you were attempting to add.

@bharel
Copy link
Author
bharel commented Feb 3, 2021 via email

@JelleZijlstra
Copy link
Member

I would agree that @no_type_check should suppress all errors within the body of a function, including in nested functions and redefinitions. I haven't checked but it might be a fairly easy fix.

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-pep-484
Projects
None yet
Development

No branches or pull requests

3 participants
0