Skip to content

Commit 1452020

Browse files
committed
Merge remote-tracking branch 'upstream/master' into conditional-overloads_backup
2 parents 4c2e98b + 18d5669 commit 1452020

File tree

6 files changed

+60
-24
lines changed

6 files changed

+60
-24
lines changed

mypy/constraints.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -581,12 +581,12 @@ def visit_callable_type(self, template: CallableType) -> List[Constraint]:
581581
if param_spec is None:
582582
# FIX what if generic
583583
res = self.infer_against_any(template.arg_types, self.actual)
584-
res.extend(infer_constraints(template.ret_type, any_type, self.direction))
585-
return res
586584
else:
587-
return [Constraint(param_spec.id,
588-
SUBTYPE_OF,
589-
callable_with_ellipsis(any_type, any_type, template.fallback))]
585+
res = [Constraint(param_spec.id,
586+
SUBTYPE_OF,
587+
callable_with_ellipsis(any_type, any_type, template.fallback))]
588+
res.extend(infer_constraints(template.ret_type, any_type, self.direction))
589+
return res
590590
elif isinstance(self.actual, Overloaded):
591591
return self.infer_against_overloaded(self.actual, template)
592592
elif isinstance(self.actual, TypeType):

mypy/test/data.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,11 @@ def parse_test_case(case: 'DataDrivenTestCase') -> None:
114114
if arg == 'skip-path-normalization':
115115
normalize_output = False
116116
if arg.startswith("version"):
117-
if arg[7:9] != ">=":
117+
compare_op = arg[7:9]
118+
if compare_op not in {">=", "=="}:
118119
raise ValueError(
119-
"{}, line {}: Only >= version checks are currently supported".format(
120+
"{}, line {}: Only >= and == version checks are currently supported"
121+
.format(
120122
case.file, item.line
121123
)
122124
)
@@ -127,9 +129,17 @@ def parse_test_case(case: 'DataDrivenTestCase') -> None:
127129
raise ValueError(
128130
'{}, line {}: "{}" is not a valid python version'.format(
129131
case.file, item.line, version_str))
130-
if not sys.version_info >= version:
131-
version_check = False
132-
132+
if compare_op == ">=":
133+
version_check = sys.version_info >= version
134+
elif compare_op == "==":
135+
if not 1 < len(version) < 4:
136+
raise ValueError(
137+
'{}, line {}: Only minor or patch version checks '
138+
'are currently supported with "==": "{}"'.format(
139+
case.file, item.line, version_str
140+
)
141+
)
142+
version_check = sys.version_info[:len(version)] == version
133143
if version_check:
134144
tmp_output = [expand_variables(line) for line in item.data]
135145
if os.path.sep == '\\' and normalize_output:

test-data/unit/check-errorcodes.test

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,8 @@ reveal_type(1) # N: Revealed type is "Literal[1]?"
3434
1 ''
3535
[out]
3636
main:1: error: invalid syntax [syntax]
37-
[out version>=3.10]
37+
[out version==3.10.0]
3838
main:1: error: invalid syntax. Perhaps you forgot a comma? [syntax]
39-
[out version>=3.10.1]
40-
main:1: error: invalid syntax [syntax]
4139

4240
[case testErrorCodeSyntaxError2]
4341
def f(): # E: Type signature has too many arguments [syntax]

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,3 +378,31 @@ class C(Generic[P, P2]):
378378
def m4(self, x: int) -> None:
379379
pass
380380
[builtins fixtures/dict.pyi]
381+
382+
[case testParamSpecOverUnannotatedDecorator]
383+
from typing import Callable, Iterator, TypeVar, ContextManager, Any
384+
from typing_extensions import ParamSpec
385+
386+
from nonexistent import deco2 # type: ignore
387+
388+
T = TypeVar("T")
389+
P = ParamSpec("P")
390+
T_co = TypeVar("T_co", covariant=True)
391+
392+
class CM(ContextManager[T_co]):
393+
def __call__(self, func: T) -> T: ...
394+
395+
def deco1(
396+
func: Callable[P, Iterator[T]]) -> Callable[P, CM[T]]: ...
397+
398+
@deco1
399+
@deco2
400+
def f():
401+
pass
402+
403+
reveal_type(f) # N: Revealed type is "def (*Any, **Any) -> __main__.CM[Any]"
404+
405+
with f() as x:
406+
pass
407+
[builtins fixtures/dict.pyi]
408+
[typing fixtures/typing-full.pyi]

test-data/unit/fine-grained-blockers.test

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ class C:
156156
a.py:1: error: invalid syntax
157157
==
158158
main:5: error: Missing positional argument "x" in call to "f" of "C"
159-
[out version>=3.10]
159+
[out version==3.10.0]
160160
==
161161
a.py:1: error: invalid syntax. Perhaps you forgot a comma?
162162
==
@@ -176,7 +176,7 @@ main:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missin
176176
a.py:1: error: invalid syntax
177177
==
178178
main:2: error: Too many arguments for "f"
179-
[out version>=3.10]
179+
[out version==3.10.0]
180180
main:1: error: Cannot find implementation or library stub for module named "a"
181181
main:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
182182
==
@@ -259,7 +259,7 @@ a.py:1: error: invalid syntax
259259
a.py:1: error: invalid syntax
260260
==
261261
a.py:2: error: Missing positional argument "x" in call to "f"
262-
[out version>=3.10]
262+
[out version==3.10.0]
263263
==
264264
a.py:1: error: invalid syntax. Perhaps you forgot a comma?
265265
==
@@ -330,7 +330,7 @@ a.py:1: error: invalid syntax
330330
main:1: error: Cannot find implementation or library stub for module named "a"
331331
main:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
332332
b.py:1: error: Cannot find implementation or library stub for module named "a"
333-
[out version>=3.10]
333+
[out version==3.10.0]
334334
==
335335
a.py:1: error: invalid syntax. Perhaps you forgot a comma?
336336
==
@@ -358,7 +358,7 @@ a.py:1: error: invalid syntax
358358
b.py:1: error: Cannot find implementation or library stub for module named "a"
359359
b.py:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
360360
main:1: error: Cannot find implementation or library stub for module named "a"
361-
[out version>=3.10]
361+
[out version==3.10.0]
362362
==
363363
a.py:1: error: invalid syntax. Perhaps you forgot a comma?
364364
==
@@ -388,7 +388,7 @@ a.py:1: error: invalid syntax
388388
==
389389
b.py:2: error: Module has no attribute "f"
390390
b.py:3: error: "int" not callable
391-
[out version>=3.10]
391+
[out version==3.10.0]
392392
==
393393
a.py:1: error: invalid syntax. Perhaps you forgot a comma?
394394
==
@@ -411,7 +411,7 @@ def f() -> None: pass
411411
<ROOT>/test-data/unit/lib-stub/blocker.pyi:2: error: invalid syntax
412412
==
413413
a.py:1: error: "int" not callable
414-
[out version>=3.10]
414+
[out version==3.10.0]
415415
==
416416
<ROOT>/test-data/unit/lib-stub/blocker.pyi:2: error: invalid syntax. Perhaps you forgot a comma?
417417
==
@@ -490,7 +490,7 @@ a.py:1: error: invalid syntax
490490
<ROOT>/test-data/unit/lib-stub/blocker.pyi:2: error: invalid syntax
491491
==
492492
a.py:2: error: "int" not callable
493-
[out version>=3.10]
493+
[out version==3.10.0]
494494
==
495495
a.py:1: error: invalid syntax. Perhaps you forgot a comma?
496496
==
@@ -515,7 +515,7 @@ a.py:1: error: invalid syntax
515515
==
516516
b.py:2: error: Incompatible return value type (got "str", expected "int")
517517
==
518-
[out version>=3.10]
518+
[out version==3.10.0]
519519
a.py:1: error: invalid syntax. Perhaps you forgot a comma?
520520
==
521521
b.py:2: error: Incompatible return value type (got "str", expected "int")

test-data/unit/parse.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -935,7 +935,7 @@ MypyFile:1(
935935
x not y
936936
[out]
937937
main:1: error: invalid syntax
938-
[out version>=3.10]
938+
[out version==3.10.0]
939939
main:1: error: invalid syntax. Perhaps you forgot a comma?
940940

941941
[case testNotIs]
@@ -946,7 +946,7 @@ x not is y # E: invalid syntax
946946
1 ~ 2
947947
[out]
948948
main:1: error: invalid syntax
949-
[out version>=3.10]
949+
[out version==3.10.0]
950950
main:1: error: invalid syntax. Perhaps you forgot a comma?
951951

952952
[case testSliceInList39]

0 commit comments

Comments
 (0)