@@ -595,13 +595,13 @@ of the above sections.
595595 This flag causes mypy to suppress errors caused by not being able to fully
596596 infer the types of global and class variables.
597597
598- .. option :: --allow-redefinition-new
598+ .. option :: --allow-redefinition
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
@@ -613,7 +613,7 @@ of the above sections.
613613 # Type of "x" is "int | str" here.
614614 return x
615615
616- Without the new flag, mypy only supports inferring optional types
616+ Without this flag, mypy only supports inferring optional types
617617 (``X | None ``) from multiple assignments. With this option enabled,
618618 mypy can infer arbitrary union types.
619619
@@ -644,26 +644,23 @@ 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
649- .. option :: --allow-redefinition
649+ .. option :: --allow-redefinition-new
650650
651- This is an alias to :option: `--allow-redefinition-old <mypy --allow-redefinition-old> `.
652- In mypy v2.0 this will point to
653- :option: `--allow-redefinition-new <mypy --allow-redefinition-new> `, and will
654- eventually became the default.
651+ Deprecated alias for :option: `--allow-redefinition <mypy --allow-redefinition> `.
655652
656653.. option :: --allow-redefinition-old
657654
658- This is an older variant of
659- :option: `--allow-redefinition-new <mypy --allow-redefinition-new > `.
655+ This is an older, more limited variant of
656+ :option: `--allow-redefinition <mypy --allow-redefinition> `.
660657 This flag enables redefinition of a variable with an
661658 arbitrary type *in some contexts *: only redefinitions within the
662659 same block and nesting depth as the original definition are allowed.
663660
664- We have no plans to remove this flag, but we expect that
665- :option: `--allow-redefinition-new <mypy --allow-redefinition-new > `
666- will replace this flag for new use cases eventually .
661+ We have no plans to remove this flag, but
662+ :option: `--allow-redefinition <mypy --allow-redefinition> `
663+ is recommended for new use cases.
667664
668665 Example where this can be useful:
669666
@@ -684,30 +681,26 @@ of the above sections.
684681 items = " 100" # valid, items now has type str
685682 items = int (items) # valid, items now has type int
686683
687- .. option :: --local-partial-types
684+ .. option :: --no- local-partial-types
688685
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:
686+ Disable local partial types to enable legacy type inference mode for
687+ containers.
694688
695- .. code-block :: python
689+ Local partial types prevent inferring a container type for a variable, when
690+ the initial assignment happens at module top level or in a class body, and
691+ the container item type is only set in a function. Example:
696692
697- a = None # Need type annotation here if using --local-partial-types
698- b: int | None = None
693+ .. code-block :: python
699694
700- class Foo :
701- bar = None # Need type annotation here if using --local-partial-types
702- baz: int | None = None
695+ a = [] # Need type annotation unless using --no-local-partial-types
703696
704- def __init__ ( self ) -> None :
705- self .bar = 1
697+ def func ( ) -> None :
698+ a.append( 1 )
706699
707- reveal_type(Foo().bar) # ' int | None' without - -local-partial-types
700+ reveal_type(a) # "list[ int]" if using --no -local-partial-types
708701
709- Note: this option is always implicitly enabled in mypy daemon and will become
710- enabled by default in mypy v2.0 release .
702+ Local partial types are enabled by default starting from mypy 2.0. The
703+ mypy daemon requires local partial types .
711704
712705.. option :: --no-implicit-reexport
713706
@@ -764,11 +757,11 @@ of the above sections.
764757 Note that :option: `--strict-equality-for-none <mypy --strict-equality-for-none> `
765758 only works in combination with :option: `--strict-equality <mypy --strict-equality> `.
766759
767- .. option :: --strict-bytes
760+ .. option :: --no- strict-bytes
768761
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 * .
762+ Treat ``bytearray `` and ``memoryview `` as subtypes of ``bytes ``. This is not true
763+ at runtime and can lead to unexpected behavior. This was the default behavior prior
764+ to mypy 2.0.
772765
773766 .. code-block :: python
774767
@@ -777,10 +770,12 @@ of the above sections.
777770 with open (" binary_file" , " wb" ) as fp:
778771 fp.write(buf)
779772
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"
773+ # Using --no-strict-bytes disables the following errors
774+ f(bytearray (b " " )) # Argument 1 to "f" has incompatible type "bytearray"; expected "bytes"
775+ f(memoryview (b " " )) # Argument 1 to "f" has incompatible type "memoryview"; expected "bytes"
782776
783- # If `f` accepts any object that implements the buffer protocol, consider using:
777+ # If `f` accepts any object that implements the buffer protocol,
778+ # consider using Buffer instead:
784779 from collections.abc import Buffer # "from typing_extensions" in Python 3.11 and earlier
785780
786781 def f (buf : Buffer) -> None :
@@ -1037,6 +1032,43 @@ beyond what incremental mode can offer, try running mypy in
10371032 Skip cache internal consistency checks based on mtime.
10381033
10391034
1035+ .. _parallel :
1036+
1037+ Parallel type-checking
1038+ **********************
1039+
1040+ By default, mypy checks all modules in the same Python process. This can be slow
1041+ for large code bases. Mypy offers experimental parallel type-checking mode using
1042+ multiple worker processes. In parallel mode, modules that do not depend om each
1043+ other are type-checked in parallel. :ref: `Incremental cache <incremental >` is
1044+ used to manage most of the shared state. Parallel type-checking also requires
1045+ :option: `--local-partial-types <mypy --no-local-partial-types> `, which is
1046+ enabled by default starting from mypy 2.0.
1047+
1048+ .. option :: -n NUMBER , --num-workers NUMBER
1049+
1050+ Use ``NUMBER `` parallel worker processes (in addition to the coordinator
1051+ process) to perform type-checking. Specifying ``--num-workers 0 `` (default)
1052+ disables parallel checking. Automatic detection of the optimal number
1053+ of workers is not supported yet.
1054+
1055+ This setting will override the ``MYPY_NUM_WORKERS `` environment
1056+ variable if it is set.
1057+
1058+ Notes:
1059+
1060+ * An import cycle is always processed as a whole by a worker process. Thus,
1061+ avoiding large import cycles in your code will *significantly * improve
1062+ type-checking speed.
1063+
1064+ * Specifying a number of workers that is larger than the number of *physical *
1065+ CPU cores is not beneficial, since mypy is usually CPU bound. Best way to
1066+ tune the number of workers on a given machine is to start from 3-4 workers
1067+ and increase the number while you see a performance improvement.
1068+
1069+ * Parallel mode requires and automatically enables :option: `--native-parser `.
1070+
1071+
10401072Advanced options
10411073****************
10421074
@@ -1110,6 +1142,11 @@ in developing or debugging mypy internals.
11101142 cause mypy to type check the contents of ``temp.py `` instead of ``original.py ``,
11111143 but error messages will still reference ``original.py ``.
11121144
1145+ .. option :: --native-parser
1146+
1147+ This enables fast Rust-based parser that parses directly to mypy AST.
1148+ It will become the default parser in one of the next mypy releases.
1149+
11131150
11141151Report generation
11151152*****************
@@ -1174,7 +1211,7 @@ format into the specified directory.
11741211Enabling incomplete/experimental features
11751212*****************************************
11761213
1177- .. option :: --enable-incomplete-feature {PreciseTupleTypes ,InlineTypedDict , TypeForm }
1214+ .. option :: --enable-incomplete-feature {PreciseTupleTypes ,InlineTypedDict}
11781215
11791216 Some features may require several mypy releases to implement, for example
11801217 due to their complexity, potential for backwards incompatibility, or
@@ -1229,8 +1266,6 @@ List of currently incomplete/experimental features:
12291266 def test_values () -> {" width" : int , " description" : str }:
12301267 return {" width" : 42 , " description" : " test" }
12311268
1232- * ``TypeForm ``: this feature enables ``TypeForm ``, as described in
1233- `PEP 747 – Annotating Type Forms <https://peps.python.org/pep-0747/>_ `.
12341269
12351270
12361271 Miscellaneous
0 commit comments