@@ -599,9 +599,9 @@ of the above sections.
599599
600600 By default, mypy won't allow a variable to be redefined with an
601601 unrelated type. This flag enables the redefinition of *unannotated *
602- variables with an arbitrary type. You will also need to enable
603- :option: `--local-partial-types <mypy --local-partial-types> `.
604- Example:
602+ variables with an arbitrary type. This also requires
603+ :option: `--local-partial-types <mypy --no- local-partial-types> `, which is
604+ enabled by default starting from mypy 2.0. Example:
605605
606606 .. code-block :: python
607607
@@ -644,7 +644,7 @@ of the above sections.
644644 reveal_type(values) # Revealed type is list[float]
645645
646646 Note: We are planning to turn this flag on by default in a future mypy
647- release, along with :option: ` --local-partial-types <mypy --local-partial-types> ` .
647+ release.
648648
649649.. option :: --allow-redefinition
650650
@@ -684,30 +684,26 @@ of the above sections.
684684 items = " 100" # valid, items now has type str
685685 items = int (items) # valid, items now has type int
686686
687- .. option :: --local-partial-types
687+ .. option :: --no- local-partial-types
688688
689- In mypy, the most common cases for partial types are variables initialized using ``None ``,
690- but without explicit ``X | None `` annotations. By default, mypy won't check partial types
691- spanning module top level or class top level. This flag changes the behavior to only allow
692- partial types at local level, therefore it disallows inferring variable type for ``None ``
693- from two assignments in different scopes. For example:
689+ Disable local partial types to enable legacy type inference mode for
690+ containers.
694691
695- .. code-block :: python
692+ Local partial types prevent inferring a container type for a variable, when
693+ the initial assignment happens at module top level or in a class body, and
694+ the container item type is only set in a function. Example:
696695
697- a = None # Need type annotation here if using --local-partial-types
698- b: int | None = None
696+ .. code-block :: python
699697
700- class Foo :
701- bar = None # Need type annotation here if using --local-partial-types
702- baz: int | None = None
698+ a = [] # Need type annotation unless using --no-local-partial-types
703699
704- def __init__ ( self ) -> None :
705- self .bar = 1
700+ def func ( ) -> None :
701+ a.append( 1 )
706702
707- reveal_type(Foo().bar) # ' int | None' without - -local-partial-types
703+ reveal_type(a) # "list[ int]" if using --no -local-partial-types
708704
709- Note: this option is always implicitly enabled in mypy daemon and will become
710- enabled by default in mypy v2.0 release .
705+ Local partial types are enabled by default starting from mypy 2.0. The
706+ mypy daemon requires local partial types .
711707
712708.. option :: --no-implicit-reexport
713709
0 commit comments