Skip to content

Commit c784e3b

Browse files
TH3CHARLieJukkaL
authored andcommitted
Add docs for --local-partial-types option (python#8201)
Resolves python#8046.
1 parent 7495340 commit c784e3b

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

docs/source/command_line.rst

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,33 @@ of the above sections.
482482
# 'items' now has type List[List[str]]
483483
...
484484
485+
.. option:: --local-partial-types
486+
487+
In mypy, the most common cases for partial types are variables initialized using ``None``,
488+
but without explicit ``Optional`` annotations. By default, mypy won't check partial types
489+
spanning module top level or class top level. This flag changes the behavior to only allow
490+
partial types at local level, therefore it disallows inferring variable type for ``None``
491+
from two assignments in different scopes. For example:
492+
493+
.. code-block:: python
494+
495+
from typing import Optional
496+
497+
a = None # Need type annotation here if using --local-partial-types
498+
b = None # type: Optional[int]
499+
500+
class Foo:
501+
bar = None # Need type annotation here if using --local-partial-types
502+
baz = None # type: Optional[int]
503+
504+
def __init__(self) -> None
505+
self.bar = 1
506+
507+
reveal_type(Foo().bar) # Union[int, None] without --local-partial-types
508+
509+
Note: this option is always implicitly enabled in mypy daemon and will become
510+
enabled by default for mypy in a future release.
511+
485512
.. option:: --no-implicit-reexport
486513

487514
By default, imported values to a module are treated as exported and mypy allows

0 commit comments

Comments
 (0)