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

Add docs for --local-partial-types option #8201

Merged
merged 5 commits into from Jan 17, 2020
Merged

Conversation

@TH3CHARLie
Copy link
Contributor

TH3CHARLie commented Dec 24, 2019

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

docs/source/command_line.rst Outdated Show resolved Hide resolved
@TH3CHARLie TH3CHARLie requested a review from JukkaL Jan 12, 2020
docs/source/command_line.rst Outdated Show resolved Hide resolved
@@ -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.

This comment has been minimized.

Copy link
@JukkaL

JukkaL Jan 13, 2020

Collaborator

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).

docs/source/command_line.rst Outdated Show resolved Hide resolved
docs/source/command_line.rst Outdated Show resolved Hide resolved
docs/source/command_line.rst Outdated Show resolved Hide resolved
l2 = [] # type: List[int]
class Foo:
bar = None # error

This comment has been minimized.

Copy link
@JukkaL

JukkaL Jan 13, 2020

Collaborator

Similar to above -- --local-partial-types causes this to be an error.

@JukkaL
JukkaL approved these changes Jan 17, 2020
Copy link
Collaborator

JukkaL left a comment

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
1 check passed
1 check passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@TH3CHARLie

This comment has been minimized.

Copy link
Contributor Author

TH3CHARLie commented Jan 17, 2020

Thanks for the review!

@TH3CHARLie TH3CHARLie deleted the TH3CHARLie:fix-8046 branch Jan 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

2 participants
You can’t perform that action at this time.