File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -482,6 +482,33 @@ of the above sections.
482
482
# 'items' now has type List[List[str]]
483
483
...
484
484
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
+
485
512
.. option :: --no-implicit-reexport
486
513
487
514
By default, imported values to a module are treated as exported and mypy allows
You can’t perform that action at this time.
0 commit comments