KEMBAR78
Add docs for --local-partial-types option by TH3CHARLie · Pull Request #8201 · python/mypy · GitHub
Skip to content

Conversation

TH3CHARLie
Copy link
Collaborator

resolves #8046, document the --local-partial-types command line option

@TH3CHARLie TH3CHARLie requested a review from JukkaL January 12, 2020 08:10
.. option:: --local-partial-types

By default, mypy won't check partial types spanning module top level or class top level.
Copy link
Collaborator

Choose a reason for 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-types

This 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
Copy link
Collaborator

Choose a reason for 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.

Copy link
Collaborator

@JukkaL JukkaL left a comment

Choose a reason for hiding this comment

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

Thanks for the updates! I have a few small tweaks that I'll do in a follow-up PR.

@JukkaL JukkaL merged commit c784e3b into python:master Jan 17, 2020
@TH3CHARLie
Copy link
Collaborator Author

Thanks for the review!

@TH3CHARLie TH3CHARLie deleted the fix-8046 branch January 17, 2020 13:45
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.

dmypy and mypy behave differently with same settings

2 participants