-
-
Notifications
You must be signed in to change notification settings - Fork 3k
feat: warn about annotations in unannotated functions #10748
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
Changes from all commits
de287b0
88f4126
8edfc53
59ffa10
6aff52e
7972b2a
a5deb24
229d53f
1c40891
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1088,7 +1088,7 @@ reveal_type(Foo().Meta.name) # N: Revealed type is "builtins.str" | |
|
||
class A: | ||
def __init__(self): | ||
self.x = None # type: int | ||
self.x = None # type: int # N: By default the bodies of functions without signature annotations are not type checked, consider using "--check-untyped-defs" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a special case, mypy does use type annotations in unannotated There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually there still may be type errors like |
||
a = None # type: A | ||
a.x = 1 | ||
a.x = '' # E: Incompatible types in assignment (expression has type "str", variable has type "int") | ||
|
@@ -1100,7 +1100,7 @@ a.x = 1 | |
a.x = '' # E: Incompatible types in assignment (expression has type "str", variable has type "int") | ||
class A: | ||
def __init__(self): | ||
self.x = None # type: int | ||
self.x = None # type: int # N: By default the bodies of functions without signature annotations are not type checked, consider using "--check-untyped-defs" | ||
|
||
|
||
-- Special cases | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1792,6 +1792,46 @@ def foo() -> None: | |
|
||
def foo2(): | ||
global bar2 | ||
bar2 = [] # type: List[str] | ||
bar2 = [] # type: List[str] # N: By default the bodies of functions without signature annotations are not type checked, consider using "--check-untyped-defs" | ||
bar2 | ||
[builtins fixtures/list.pyi] | ||
|
||
|
||
-- Annotated assignment statement | ||
-- ------------------- | ||
|
||
|
||
[case testUnannotatedFunctionWithAnnotatedStatements] | ||
def foo(): | ||
a = 1 # type: int # N: By default the bodies of functions without signature annotations are not type checked, consider using "--check-untyped-defs" | ||
b = '' # type: int # N: By default the bodies of functions without signature annotations are not type checked, consider using "--check-untyped-defs" | ||
|
||
[case testUnannotatedFunctionWithAnnotatedStatementsAndFlag] | ||
# flags: --check-untyped-defs | ||
def foo() -> None: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same question here, you probably need to remove |
||
a = 1 # type: int | ||
b = '' # type: int # E: Incompatible types in assignment (expression has type "str", variable has type "int") | ||
|
||
[case testAnnotatedFunctionWithAnnotatedStatements] | ||
def foo() -> None: | ||
a = 1 # type: int | ||
b = '' # type: int # E: Incompatible types in assignment (expression has type "str", variable has type "int") | ||
|
||
[case testUnannotatedFunctionWithNewSyntaxAnnotatedStatements] | ||
def foo(): | ||
a: int = 1 # N: By default the bodies of functions without signature annotations are not type checked, consider using "--check-untyped-defs" | ||
b: int = '' # N: By default the bodies of functions without signature annotations are not type checked, consider using "--check-untyped-defs" | ||
c: bool # N: By default the bodies of functions without signature annotations are not type checked, consider using "--check-untyped-defs" | ||
|
||
[case testUnannotatedFunctionWithNewSyntaxAnnotatedStatementsAndFlag] | ||
# flags: --check-untyped-defs | ||
def foo() -> None: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the purpose of this test? I think you maybe wanted to check that the note is not shown if |
||
a: int = 1 | ||
b: int = '' # E: Incompatible types in assignment (expression has type "str", variable has type "int") | ||
c: bool | ||
|
||
[case testAnnotatedFunctionWithNewSyntaxAnnotatedStatements] | ||
def foo() -> None: | ||
a: int = 1 | ||
b: int = '' # E: Incompatible types in assignment (expression has type "str", variable has type "int") | ||
c: bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to just use
s.unanalyzed_type is not None
instead of adding the new attribute?