Skip to content

Commit e24b373

Browse files
committed
Fixes from rebase
1 parent 4f29231 commit e24b373

14 files changed

+1295
-1001
lines changed

.mypy/baseline.json

+1,256-985
Large diffs are not rendered by default.

mypy/dmypy/client.py

+14-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import sys
1515
import time
1616
import traceback
17+
from argparse import RawTextHelpFormatter
1718
from typing import Any, Callable, Mapping, NoReturn
1819

1920
from mypy.dmypy_os import alive, kill
@@ -32,7 +33,10 @@ def __init__(self, prog: str) -> None:
3233

3334

3435
parser = argparse.ArgumentParser(
35-
prog="dmypy", description="Client for mypy daemon mode", fromfile_prefix_chars="@"
36+
prog="dmypy",
37+
description="Client for mypy daemon mode",
38+
fromfile_prefix_chars="@",
39+
formatter_class=RawTextHelpFormatter,
3640
)
3741
parser.set_defaults(action=None)
3842
parser.add_argument(
@@ -42,7 +46,7 @@ def __init__(self, prog: str) -> None:
4246
"-V",
4347
"--version",
4448
action="version",
45-
version=f"Basedmypy Daemon {__based_version__}\n" f"Based on %(prog)s {__version__}",
49+
version=f"Basedmypy Daemon {__based_version__}\nBased on %(prog)s {__version__}",
4650
help="Show program's version number and exit",
4751
)
4852
subparsers = parser.add_subparsers()
@@ -248,6 +252,7 @@ def __init__(self, prog: str) -> None:
248252
"flags", metavar="FLAG", nargs="*", type=str, help="Regular mypy flags (precede with --)"
249253
)
250254
p.add_argument("--options-data", help=argparse.SUPPRESS)
255+
p.add_argument("--legacy", action="store_true", help=argparse.SUPPRESS)
251256
help_parser = p = subparsers.add_parser("help")
252257

253258
del p
@@ -606,8 +611,12 @@ def do_hang(args: argparse.Namespace) -> None:
606611
def do_daemon(args: argparse.Namespace) -> None:
607612
"""Serve requests in the foreground."""
608613
# Lazy import so this import doesn't slow down other commands.
614+
import mypy.options
609615
from mypy.dmypy_server import Server, process_start_options
610616

617+
if args.legacy:
618+
mypy.options._based = False
619+
611620
if args.options_data:
612621
from mypy.options import Options
613622

@@ -622,6 +631,9 @@ def do_daemon(args: argparse.Namespace) -> None:
622631
else:
623632
options = process_start_options(args.flags, allow_sources=False)
624633
timeout = args.timeout
634+
if args.legacy:
635+
if not os.getenv("__MYPY_UNDER_TEST__"):
636+
mypy.options._based = True
625637
Server(options, args.status_file, timeout=timeout).serve()
626638

627639

mypy/dmypy_server.py

+2
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ def daemonize(
5858
command = [sys.executable, "-m", "mypy.dmypy", "--status-file", status_file, "daemon"]
5959
pickled_options = pickle.dumps((options.snapshot(), timeout, log_file))
6060
command.append(f'--options-data="{base64.b64encode(pickled_options).decode()}"')
61+
if not mypy.options._based:
62+
command.append("--legacy")
6163
info = STARTUPINFO()
6264
info.dwFlags = 0x1 # STARTF_USESHOWWINDOW aka use wShowWindow's value
6365
info.wShowWindow = 0 # SW_HIDE aka make the window invisible

mypy/expandtype.py

+3
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,9 @@ def expand_unpack_with_variables(
488488
"""
489489
if isinstance(t.type, TypeVarTupleType):
490490
repl = get_proper_type(variables.get(t.type.id, t))
491+
if isinstance(repl, UnionType):
492+
# the type was joined (based) instead of `meet`ed, get the right hand side
493+
repl = get_proper_type(repl.items[1])
491494
if isinstance(repl, TupleType):
492495
return repl.items
493496
elif isinstance(repl, Instance) and repl.type.fullname == "builtins.tuple":

mypy/main.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1296,7 +1296,7 @@ def add_invertible_flag(
12961296
based_enabled_codes = (
12971297
{
12981298
"no-untyped-usage",
1299-
"partially-defined",
1299+
"possibly-undefined",
13001300
"redundant-expr",
13011301
"truthy-bool",
13021302
"ignore-without-code",

mypy/messages.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -2350,7 +2350,9 @@ def format_literal_value(typ: LiteralType) -> str:
23502350
base_str = itype.type.name
23512351
if not itype.args:
23522352
# No type arguments, just return the type name
2353-
return TypeStrVisitor.strip_builtins(base_str)
2353+
if not verbosity:
2354+
return TypeStrVisitor.strip_builtins(base_str)
2355+
return base_str
23542356
elif itype.type.fullname == "builtins.tuple":
23552357
item_type_str = format(itype.args[0])
23562358
if not mypy.options._based:

mypy/semanal.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050

5151
from __future__ import annotations
5252

53-
from contextlib import contextmanager
53+
from contextlib import contextmanager, nullcontext
5454
from typing import Any, Callable, Collection, Iterable, Iterator, List, TypeVar, cast
5555
from typing_extensions import Final, TypeAlias as _TypeAlias
5656

@@ -3347,13 +3347,13 @@ def is_annotated_protocol_member(self, s: AssignmentStmt) -> bool:
33473347
)
33483348

33493349
def analyze_simple_literal_type(
3350-
self, rvalue: Expression, is_final: bool, do_bools=False
3350+
self, rvalue: Expression, is_final: bool, do_inner=False
33513351
) -> Type | None:
33523352
"""Return builtins.int if rvalue is an int literal, etc.
33533353
33543354
If this is a 'Final' context, we return "Literal[...]" instead.
33553355
"""
3356-
if self.function_stack and not do_bools:
3356+
if self.function_stack and not do_inner:
33573357
# Skip inside a function; this is to avoid confusing
33583358
# the code that handles dead code due to isinstance()
33593359
# inside type variables with value restrictions (like
@@ -4898,6 +4898,10 @@ def visit_call_expr(self, expr: CallExpr) -> None:
48984898
expr.analyzed = OpExpr("divmod", expr.args[0], expr.args[1])
48994899
expr.analyzed.line = expr.line
49004900
expr.analyzed.accept(self)
4901+
elif refers_to_fullname(expr.callee, "typing.TypeVar"):
4902+
for a, a_name in zip(expr.args, expr.arg_names):
4903+
with self.allow_unbound_tvars_set() if a_name == "bound" else nullcontext():
4904+
a.accept(self)
49014905
else:
49024906
# Normal call expression.
49034907
for a in expr.args:
@@ -6671,7 +6675,7 @@ def is_unannotated_any(typ_: Type) -> bool:
66716675
typ = None
66726676
if arg.variable.is_inferred and arg.initializer:
66736677
arg.initializer.accept(self)
6674-
typ = self.analyze_simple_literal_type(arg.initializer, False, do_bools=True)
6678+
typ = self.analyze_simple_literal_type(arg.initializer, False, do_inner=True)
66756679
arg_types.append(typ or UntypedType())
66766680
ret_type = None
66776681
if self.options.default_return and self.options.disallow_untyped_defs:
@@ -6706,7 +6710,7 @@ def is_unannotated_any(typ_: Type) -> bool:
67066710
if is_unannotated_any(defn.type.arg_types[i]):
67076711
if arg.variable.is_inferred and arg.initializer:
67086712
ret = self.analyze_simple_literal_type(
6709-
arg.initializer, False, do_bools=True
6713+
arg.initializer, False, do_inner=True
67106714
)
67116715
if ret:
67126716
defn.type.arg_types[i] = ret

mypy/stubtest.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ def _verify_final(
401401
) -> Iterator[Error]:
402402
try:
403403

404-
class SubClass(runtime): # type: ignore[misc]
404+
class SubClass(runtime): # type: ignore[no-subclass-any]
405405
pass
406406

407407
except TypeError:

mypy/test/data.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ def split_test_cases(
651651
line_no += data.count("\n") + 1
652652

653653
# Record existing tests to prevent duplicates:
654-
test_names.update({name})
654+
test_names.update({name}) # type: ignore[no-untyped-call]
655655

656656

657657
class DataSuiteCollector(pytest.Class):

mypy/test/testdaemon.py

+1
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ def run_cmd(input: str) -> tuple[int, str]:
9191
input = sys.executable + " -m" + input
9292
env = os.environ.copy()
9393
env["PYTHONPATH"] = PREFIX
94+
env["__MYPY_UNDER_TEST__"] = "1"
9495
try:
9596
output = subprocess.check_output(
9697
input, shell=True, stderr=subprocess.STDOUT, text=True, cwd=test_temp_dir, env=env

mypy_self_check.ini

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@ nonlocal_partial_types = True
1313
allow_any_expr = True
1414
allow_any_explicit = True
1515
allow_any_decorated = True
16-
allow_subclassing_any = True
1716
no_warn_unreachable = True
1817
implicit_reexport = True
1918
disallow_redefinition = True
20-
disable_error_code = truthy-bool, no-untyped-usage, partially-defined
19+
disable_error_code = truthy-bool, no-untyped-usage, possibly-undefined
2120
bare_literals = True
2221

2322
[mypy-mypy.*,mypyc.*]

test-data/unit/check-parameter-specification.test

-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ def foo3(x: Concatenate[int, P]) -> int: ... # E: Invalid location for Concaten
3131
# N: You can use Concatenate as the first argument to Callable
3232

3333
def foo4(x: List[P]) -> None: ... # E: Invalid location for ParamSpec "P" \
34-
# E: Invalid location for ParamSpec "P" \
3534
# N: You can use ParamSpec as the first argument to Callable, e.g., 'Callable[P, int]'
3635

3736
def foo5(x: Callable[[int, str], P]) -> None: ... # E: Invalid location for ParamSpec "P" \

test-data/unit/check-selftype.test

+2-1
Original file line numberDiff line numberDiff line change
@@ -1401,7 +1401,8 @@ reveal_type(var) # N: Revealed type is "Any"
14011401
def foo() -> Self: ... # E: Self type is only allowed in annotations within class definition
14021402
reveal_type(foo) # N: Revealed type is "def () -> Any"
14031403

1404-
bad: Callable[[Self], Self] # E: Self type is only allowed in annotations within class definition
1404+
bad: Callable[[Self], Self] # E: Self type is only allowed in annotations within class definition \
1405+
# E: Self type is only allowed in annotations within class definition
14051406
reveal_type(bad) # N: Revealed type is "def (Any) -> Any"
14061407

14071408
def func() -> None:

test-data/unit/pythoneval.test

+1-1
Original file line numberDiff line numberDiff line change
@@ -1855,6 +1855,6 @@ _testTupleWithDifferentArgsPy310.py:17: note: Revealed type is "Union[builtins.t
18551855
_testTupleWithDifferentArgsPy310.py:18: note: Revealed type is "Tuple[builtins.float, builtins.str]"
18561856
_testTupleWithDifferentArgsPy310.py:19: note: Revealed type is "builtins.tuple[builtins.float, ...]"
18571857
_testTupleWithDifferentArgsPy310.py:20: note: Revealed type is "builtins.list[Tuple[builtins.int, builtins.str]]"
1858-
_testTupleWithDifferentArgsPy310.py:26: error: Invalid type: try using Literal[1] instead?
1858+
_testTupleWithDifferentArgsPy310.py:26: error: "1" is a bare literal and cannot be used here, try Literal[1] instead?
18591859
_testTupleWithDifferentArgsPy310.py:27: error: Unexpected "..."
18601860
_testTupleWithDifferentArgsPy310.py:30: note: Revealed type is "builtins.tuple[builtins.object, ...]"

0 commit comments

Comments
 (0)