@@ -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
@@ -764,11 +760,11 @@ of the above sections.
764760 Note that :option: `--strict-equality-for-none <mypy --strict-equality-for-none> `
765761 only works in combination with :option: `--strict-equality <mypy --strict-equality> `.
766762
767- .. option :: --strict-bytes
763+ .. option :: --no- strict-bytes
768764
769- By default, mypy treats ``bytearray `` and ``memoryview `` as subtypes of ``bytes `` which
770- is not true at runtime. Use this flag to disable this behavior. `` --strict-bytes `` will
771- be enabled by default in * mypy 2.0 * .
765+ Treat ``bytearray `` and ``memoryview `` as subtypes of ``bytes ``. This is not true
766+ at runtime and can lead to unexpected behavior. This was the default behavior prior
767+ to mypy 2.0.
772768
773769 .. code-block :: python
774770
@@ -777,10 +773,12 @@ of the above sections.
777773 with open (" binary_file" , " wb" ) as fp:
778774 fp.write(buf)
779775
780- f(bytearray (b " " )) # error: Argument 1 to "f" has incompatible type "bytearray"; expected "bytes"
781- f(memoryview (b " " )) # error: Argument 1 to "f" has incompatible type "memoryview"; expected "bytes"
776+ # Using --no-strict-bytes disables the following errors
777+ f(bytearray (b " " )) # Argument 1 to "f" has incompatible type "bytearray"; expected "bytes"
778+ f(memoryview (b " " )) # Argument 1 to "f" has incompatible type "memoryview"; expected "bytes"
782779
783- # If `f` accepts any object that implements the buffer protocol, consider using:
780+ # If `f` accepts any object that implements the buffer protocol,
781+ # consider using Buffer instead:
784782 from collections.abc import Buffer # "from typing_extensions" in Python 3.11 and earlier
785783
786784 def f (buf : Buffer) -> None :
0 commit comments