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
| @@ -482,6 +482,32 @@ of the above sections. | |||
| # 'items' now has type List[List[str]] | |||
| ... | |||
|
|
|||
| .. option:: --local-partial-types | |||
|
|
|||
| By default, mypy won't check partial types spanning module top level or class top level. | |||
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This sentence is pretty vague. It would be better to also introduce the concept "partial types" before discussing it.
This is an important case where this option makes a difference:
class A:
x = None # Need type annotation here if using --local-partial-types
def __init__(self) -> None:
self.x = 1
reveal_type(A().x) # Union[int, None] without --local-partial-typesThis example also makes it easier to see why this is called "local partial types" -- it disallows inferring variable type from two assignments in different scopes (for example, in class body and inside a method).
| l2 = [] # type: List[int] | ||
|
|
||
| class Foo: | ||
| bar = None # error |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Similar to above -- --local-partial-types causes this to be an error.
|
Thanks for the review! |
resolves #8046, document the
--local-partial-typescommand line option