Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f8127c8

Browse files
authored
Make --local-partial-types the default (#21163)
1 parent 30e8f1d commit f8127c8

8 files changed

Lines changed: 16 additions & 8 deletions

File tree

mypy/dmypy_server.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ def process_start_options(flags: list[str], allow_sources: bool) -> Options:
151151
sys.exit("dmypy: start/restart should not disable incremental mode")
152152
if options.follow_imports not in ("skip", "error", "normal"):
153153
sys.exit("dmypy: follow-imports=silent not supported")
154+
if not options.local_partial_types:
155+
sys.exit("dmypy: disabling local-partial-types not supported")
154156
return options
155157

156158

mypy/main.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1266,7 +1266,13 @@ def add_invertible_flag(
12661266
parser.add_argument("--test-env", action="store_true", help=argparse.SUPPRESS)
12671267
# --local-partial-types disallows partial types spanning module top level and a function
12681268
# (implicitly defined in fine-grained incremental mode)
1269-
add_invertible_flag("--local-partial-types", default=False, help=argparse.SUPPRESS)
1269+
add_invertible_flag(
1270+
"--no-local-partial-types",
1271+
inverse="--local-partial-types",
1272+
default=True,
1273+
dest="local_partial_types",
1274+
help=argparse.SUPPRESS,
1275+
)
12701276
# --native-parser enables the native parser (experimental)
12711277
add_invertible_flag("--native-parser", default=False, help=argparse.SUPPRESS)
12721278
# --logical-deps adds some more dependencies that are not semantically needed, but

mypy/options.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ def __init__(self) -> None:
381381
self.dump_deps = False
382382
self.logical_deps = False
383383
# If True, partial types can't span a module top level and a function
384-
self.local_partial_types = False
384+
self.local_partial_types = True
385385
# If True, use the native parser (experimental)
386386
self.native_parser = False
387387
# Some behaviors are changed when using Bazel (https://bazel.build).

mypyc/test-data/run-classes.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4363,7 +4363,7 @@ from __future__ import annotations
43634363

43644364
from mypy_extensions import mypyc_attr
43654365

4366-
a = []
4366+
a: list[int] = []
43674367

43684368
@mypyc_attr(free_list_len=1)
43694369
class Foo:

mypyc/test-data/run-tuples.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ def test_final_tuple_not_in() -> None:
339339

340340
assert 'x' not in TUP0
341341

342-
log = []
342+
log: list[str] = []
343343

344344
def f_a() -> str:
345345
log.append('f_a')

test-data/unit/check-custom-plugin.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -996,7 +996,7 @@ class M(type):
996996
attr = 'test'
997997

998998
class B:
999-
attr = None
999+
attr = b'bytes'
10001000

10011001
class Cls(B, metaclass=M):
10021002
pass

test-data/unit/check-functions.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2642,7 +2642,7 @@ reveal_type(bar(None)) # N: Revealed type is "None"
26422642
[out]
26432643

26442644
[case testNoComplainInferredNone]
2645-
# flags: --no-strict-optional
2645+
# flags: --no-strict-optional --no-local-partial-types
26462646
from typing import TypeVar, Optional
26472647
T = TypeVar('T')
26482648
def X(val: T) -> T: ...
@@ -2655,7 +2655,7 @@ xx: Optional[int] = X(x_in)
26552655
from typing import TypeVar, Optional
26562656
T = TypeVar('T')
26572657
def X(val: T) -> T: ...
2658-
x_in = None
2658+
x_in = X(None)
26592659
def Y(x: Optional[str] = X(x_in)): ...
26602660

26612661
xx: Optional[int] = X(x_in)

test-data/unit/check-redefine2.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1112,7 +1112,7 @@ if int():
11121112
x = ""
11131113

11141114
[file b.py]
1115-
# mypy: allow-redefinition-new
1115+
# mypy: local-partial-types=false, allow-redefinition-new
11161116
x = 0
11171117
if int():
11181118
x = ""

0 commit comments

Comments
 (0)