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

Support @no_type_check for classes #10162

Closed
wants to merge 1 commit into from
Closed

Support @no_type_check for classes #10162

wants to merge 1 commit into from

Conversation

kamilturek
Copy link
Contributor

Description

Closes #607.

Skip checking class scope if typing.no_type_check decorator has been applied on class definition.

if not any(refers_to_fullname(decorator,
'typing.no_type_check')
for decorator in defn.decorators):
self.accept(defn.defs)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type checking populates some information that other parts of the type checker may rely on. So this needs to be more elaborate.

For example, this shouldn't generate errors:

import typing

@typing.no_type_check
class A:
    a = int()

    def f(self) -> None:
        self.b = int()

a = A()
a.a  # Cannot determine type of "a"
a.b  # Cannot determine type of "b"

One way to deal with this is to give everything in the class the type Any. We'd still no type checking, but it actually wouldn't do much. We use in_checked_function() in mypy.checker to do this. You can add some check for no_type_check decorator there (maybe via a bool attribute flag) so that in_checked_function() returns False inside the class.

@AlexWaygood
Copy link
Member

This now has merge conflicts, and Jukka's review from two years ago still hasn't been addressed,so I'm closing this PR. If you're still interested in working on this issue, please feel free to open a new PR @kamilturek!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support @no_type_check for classes
3 participants