diff --git a/mypy/dmypy_server.py b/mypy/dmypy_server.py index 5b0e03282a4a..614b757c774d 100644 --- a/mypy/dmypy_server.py +++ b/mypy/dmypy_server.py @@ -151,6 +151,8 @@ def process_start_options(flags: list[str], allow_sources: bool) -> Options: sys.exit("dmypy: start/restart should not disable incremental mode") if options.follow_imports not in ("skip", "error", "normal"): sys.exit("dmypy: follow-imports=silent not supported") + if not options.local_partial_types: + sys.exit("dmypy: disabling local-partial-types not supported") return options diff --git a/mypy/main.py b/mypy/main.py index f4d6b18e58b6..8fecb720cc78 100644 --- a/mypy/main.py +++ b/mypy/main.py @@ -1254,7 +1254,13 @@ def add_invertible_flag( parser.add_argument("--test-env", action="store_true", help=argparse.SUPPRESS) # --local-partial-types disallows partial types spanning module top level and a function # (implicitly defined in fine-grained incremental mode) - add_invertible_flag("--local-partial-types", default=False, help=argparse.SUPPRESS) + add_invertible_flag( + "--no-local-partial-types", + inverse="--local-partial-types", + default=True, + dest="local_partial_types", + help=argparse.SUPPRESS, + ) # --native-parser enables the native parser (experimental) add_invertible_flag("--native-parser", default=False, help=argparse.SUPPRESS) # --logical-deps adds some more dependencies that are not semantically needed, but diff --git a/mypy/options.py b/mypy/options.py index 79ca75c58be6..77a3e4fd0584 100644 --- a/mypy/options.py +++ b/mypy/options.py @@ -380,7 +380,7 @@ def __init__(self) -> None: self.dump_deps = False self.logical_deps = False # If True, partial types can't span a module top level and a function - self.local_partial_types = False + self.local_partial_types = True # If True, use the native parser (experimental) self.native_parser = False # Some behaviors are changed when using Bazel (https://bazel.build). diff --git a/mypyc/test-data/run-classes.test b/mypyc/test-data/run-classes.test index 877c40699cda..b3526b0dc7fb 100644 --- a/mypyc/test-data/run-classes.test +++ b/mypyc/test-data/run-classes.test @@ -4363,7 +4363,7 @@ from __future__ import annotations from mypy_extensions import mypyc_attr -a = [] +a: list[int] = [] @mypyc_attr(free_list_len=1) class Foo: diff --git a/mypyc/test-data/run-tuples.test b/mypyc/test-data/run-tuples.test index e2e8358bb43e..b410d8e4ba38 100644 --- a/mypyc/test-data/run-tuples.test +++ b/mypyc/test-data/run-tuples.test @@ -339,7 +339,7 @@ def test_final_tuple_not_in() -> None: assert 'x' not in TUP0 -log = [] +log: list[str] = [] def f_a() -> str: log.append('f_a') diff --git a/test-data/unit/check-custom-plugin.test b/test-data/unit/check-custom-plugin.test index 7b1a2c2a91d7..dd1de1265b59 100644 --- a/test-data/unit/check-custom-plugin.test +++ b/test-data/unit/check-custom-plugin.test @@ -996,7 +996,7 @@ class M(type): attr = 'test' class B: - attr = None + attr = b'bytes' class Cls(B, metaclass=M): pass diff --git a/test-data/unit/check-functions.test b/test-data/unit/check-functions.test index 80a40d3ef179..a0e31fa23ce4 100644 --- a/test-data/unit/check-functions.test +++ b/test-data/unit/check-functions.test @@ -2622,7 +2622,7 @@ reveal_type(bar(None)) # N: Revealed type is "None" [out] [case testNoComplainInferredNone] -# flags: --no-strict-optional +# flags: --no-strict-optional --no-local-partial-types from typing import TypeVar, Optional T = TypeVar('T') def X(val: T) -> T: ... @@ -2635,7 +2635,7 @@ xx: Optional[int] = X(x_in) from typing import TypeVar, Optional T = TypeVar('T') def X(val: T) -> T: ... -x_in = None +x_in = X(None) def Y(x: Optional[str] = X(x_in)): ... xx: Optional[int] = X(x_in) diff --git a/test-data/unit/check-redefine2.test b/test-data/unit/check-redefine2.test index b1a30784b99c..d8a7ccbfc4a4 100644 --- a/test-data/unit/check-redefine2.test +++ b/test-data/unit/check-redefine2.test @@ -1112,7 +1112,7 @@ if int(): x = "" [file b.py] -# mypy: allow-redefinition-new +# mypy: local-partial-types=false, allow-redefinition-new x = 0 if int(): x = ""