@@ -551,7 +551,7 @@ potentially problematic or redundant in some way.
551551 .. note ::
552552
553553 Mypy currently cannot detect and report unreachable or redundant code
554- inside any functions using :ref: `type-variable-value-restriction `.
554+ inside any functions using :ref: `value-constrained type variables < value-constrained-type-variables > `.
555555
556556 This limitation will be removed in future releases of mypy.
557557
@@ -598,10 +598,10 @@ of the above sections.
598598.. option :: --allow-redefinition-new
599599
600600 By default, mypy won't allow a variable to be redefined with an
601- unrelated type. This * experimental * flag enables the redefinition of
602- unannotated variables with an arbitrary type. You will also need to enable
603- :option: `--local-partial-types <mypy --local-partial-types> `.
604- Example:
601+ unrelated type. This flag enables the redefinition of * unannotated *
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
@@ -631,12 +631,30 @@ of the above sections.
631631 # Type of "x" is "str" here.
632632 ...
633633
634+ Function arguments are special, changing their type within function body
635+ is allowed even if they are annotated, but that annotation is used to infer
636+ types of r.h.s. of all subsequent assignments. Such middle-ground semantics
637+ provides good balance for majority of common use cases. For example:
638+
639+ .. code-block :: python
640+
641+ def process (values : list[float ]) -> None :
642+ if not values:
643+ values = [0 , 0 , 0 ]
644+ reveal_type(values) # Revealed type is list[float]
645+
634646 Note: We are planning to turn this flag on by default in a future mypy
635- release, along with :option: `--local-partial-types <mypy --local-partial-types> `.
636- The feature is still experimental, and the semantics may still change.
647+ release.
637648
638649.. option :: --allow-redefinition
639650
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.
655+
656+ .. option :: --allow-redefinition-old
657+
640658 This is an older variant of
641659 :option: `--allow-redefinition-new <mypy --allow-redefinition-new> `.
642660 This flag enables redefinition of a variable with an
@@ -666,30 +684,26 @@ of the above sections.
666684 items = " 100" # valid, items now has type str
667685 items = int (items) # valid, items now has type int
668686
669- .. option :: --local-partial-types
687+ .. option :: --no- local-partial-types
670688
671- In mypy, the most common cases for partial types are variables initialized using ``None ``,
672- but without explicit ``X | None `` annotations. By default, mypy won't check partial types
673- spanning module top level or class top level. This flag changes the behavior to only allow
674- partial types at local level, therefore it disallows inferring variable type for ``None ``
675- from two assignments in different scopes. For example:
689+ Disable local partial types to enable legacy type inference mode for
690+ containers.
676691
677- .. 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:
678695
679- a = None # Need type annotation here if using --local-partial-types
680- b: int | None = None
696+ .. code-block :: python
681697
682- class Foo :
683- bar = None # Need type annotation here if using --local-partial-types
684- baz: int | None = None
698+ a = [] # Need type annotation unless using --no-local-partial-types
685699
686- def __init__ ( self ) -> None :
687- self .bar = 1
700+ def func ( ) -> None :
701+ a.append( 1 )
688702
689- reveal_type(Foo().bar) # ' int | None' without - -local-partial-types
703+ reveal_type(a) # "list[ int]" if using --no -local-partial-types
690704
691- Note: this option is always implicitly enabled in mypy daemon and will become
692- enabled by default for mypy in a future release .
705+ Local partial types are enabled by default starting from mypy 2.0. The
706+ mypy daemon requires local partial types .
693707
694708.. option :: --no-implicit-reexport
695709
@@ -746,11 +760,11 @@ of the above sections.
746760 Note that :option: `--strict-equality-for-none <mypy --strict-equality-for-none> `
747761 only works in combination with :option: `--strict-equality <mypy --strict-equality> `.
748762
749- .. option :: --strict-bytes
763+ .. option :: --no- strict-bytes
750764
751- By default, mypy treats ``bytearray `` and ``memoryview `` as subtypes of ``bytes `` which
752- is not true at runtime. Use this flag to disable this behavior. `` --strict-bytes `` will
753- 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.
754768
755769 .. code-block :: python
756770
@@ -759,10 +773,12 @@ of the above sections.
759773 with open (" binary_file" , " wb" ) as fp:
760774 fp.write(buf)
761775
762- f(bytearray (b " " )) # error: Argument 1 to "f" has incompatible type "bytearray"; expected "bytes"
763- 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"
764779
765- # 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:
766782 from collections.abc import Buffer # "from typing_extensions" in Python 3.11 and earlier
767783
768784 def f (buf : Buffer) -> None :
@@ -1000,9 +1016,10 @@ beyond what incremental mode can offer, try running mypy in
10001016 writing to the cache, use ``--cache-dir=/dev/null `` (UNIX)
10011017 or ``--cache-dir=nul `` (Windows).
10021018
1003- .. option :: --sqlite-cache
1019+ .. option :: --no- sqlite-cache
10041020
1005- Use an `SQLite `_ database to store the cache.
1021+ Avoid using `SQLite `_ database to store the cache, instead write cache data
1022+ out to individual files.
10061023
10071024.. option :: --cache-fine-grained
10081025
0 commit comments