Skip to content

Commit bd4bde2

Browse files
Merge branch 'python:master' into str-lower-upper
2 parents 7049d8b + de23d08 commit bd4bde2

File tree

5 files changed

+55
-21
lines changed

5 files changed

+55
-21
lines changed

misc/profile_self_check.py renamed to misc/profile_check.py

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
"""Compile mypy using mypyc and profile self-check using perf.
1+
"""Compile mypy using mypyc and profile type checking using perf.
2+
3+
By default does a self check.
24
35
Notes:
46
- Only Linux is supported for now (TODO: add support for other profilers)
@@ -23,6 +25,8 @@
2325
CFLAGS="-O2 -g -fno-omit-frame-pointer"
2426
"""
2527

28+
from __future__ import annotations
29+
2630
import argparse
2731
import glob
2832
import os
@@ -41,24 +45,28 @@
4145
TARGET_DIR = "mypy.profile.tmpdir"
4246

4347

44-
def _profile_self_check(target_dir: str) -> None:
48+
def _profile_type_check(target_dir: str, code: str | None) -> None:
4549
cache_dir = os.path.join(target_dir, ".mypy_cache")
4650
if os.path.exists(cache_dir):
4751
shutil.rmtree(cache_dir)
48-
files = []
49-
for pat in "mypy/*.py", "mypy/*/*.py", "mypyc/*.py", "mypyc/test/*.py":
50-
files.extend(glob.glob(pat))
51-
self_check_cmd = ["python", "-m", "mypy", "--config-file", "mypy_self_check.ini"] + files
52-
cmdline = ["perf", "record", "-g"] + self_check_cmd
52+
args = []
53+
if code is None:
54+
args.extend(["--config-file", "mypy_self_check.ini"])
55+
for pat in "mypy/*.py", "mypy/*/*.py", "mypyc/*.py", "mypyc/test/*.py":
56+
args.extend(glob.glob(pat))
57+
else:
58+
args.extend(["-c", code])
59+
check_cmd = ["python", "-m", "mypy"] + args
60+
cmdline = ["perf", "record", "-g"] + check_cmd
5361
t0 = time.time()
5462
subprocess.run(cmdline, cwd=target_dir, check=True)
5563
elapsed = time.time() - t0
5664
print(f"{elapsed:.2f}s elapsed")
5765

5866

59-
def profile_self_check(target_dir: str) -> None:
67+
def profile_type_check(target_dir: str, code: str | None) -> None:
6068
try:
61-
_profile_self_check(target_dir)
69+
_profile_type_check(target_dir, code)
6270
except subprocess.CalledProcessError:
6371
print("\nProfiling failed! You may missing some permissions.")
6472
print("\nThis may help (note that it has security implications):")
@@ -92,7 +100,7 @@ def main() -> None:
92100
check_requirements()
93101

94102
parser = argparse.ArgumentParser(
95-
description="Compile mypy and profile self checking using 'perf'."
103+
description="Compile mypy and profile type checking using 'perf' (by default, self check)."
96104
)
97105
parser.add_argument(
98106
"--multi-file",
@@ -102,9 +110,17 @@ def main() -> None:
102110
parser.add_argument(
103111
"--skip-compile", action="store_true", help="use compiled mypy from previous run"
104112
)
113+
parser.add_argument(
114+
"-c",
115+
metavar="CODE",
116+
default=None,
117+
type=str,
118+
help="profile type checking Python code fragment instead of mypy self-check",
119+
)
105120
args = parser.parse_args()
106121
multi_file: bool = args.multi_file
107122
skip_compile: bool = args.skip_compile
123+
code: str | None = args.c
108124

109125
target_dir = TARGET_DIR
110126

@@ -116,7 +132,7 @@ def main() -> None:
116132
elif not os.path.isdir(target_dir):
117133
sys.exit("error: Can't find compile mypy from previous run -- can't use --skip-compile")
118134

119-
profile_self_check(target_dir)
135+
profile_type_check(target_dir, code)
120136

121137
print()
122138
print('NOTE: Compile CPython using CFLAGS="-O2 -g -fno-omit-frame-pointer" for good results')

mypy/subtypes.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -155,15 +155,13 @@ def is_subtype(
155155
options=options,
156156
)
157157
else:
158-
assert not any(
159-
{
160-
ignore_type_params,
161-
ignore_pos_arg_names,
162-
ignore_declared_variance,
163-
always_covariant,
164-
ignore_promotions,
165-
options,
166-
}
158+
assert (
159+
not ignore_type_params
160+
and not ignore_pos_arg_names
161+
and not ignore_declared_variance
162+
and not always_covariant
163+
and not ignore_promotions
164+
and options is None
167165
), "Don't pass both context and individual flags"
168166
if type_state.is_assumed_subtype(left, right):
169167
return True

mypy/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# - Release versions have the form "1.2.3".
99
# - Dev versions have the form "1.2.3+dev" (PLUS sign to conform to PEP 440).
1010
# - Before 1.0 we had the form "0.NNN".
11-
__version__ = "1.17.0+dev"
11+
__version__ = "1.18.0+dev"
1212
base_version = __version__
1313

1414
mypy_dir = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))

mypyc/irbuild/ll_builder.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1507,6 +1507,10 @@ def compare_tuples(self, lhs: Value, rhs: Value, op: str, line: int = -1) -> Val
15071507
assert isinstance(lhs.type, RTuple) and isinstance(rhs.type, RTuple)
15081508
equal = True if op == "==" else False
15091509
result = Register(bool_rprimitive)
1510+
# tuples of different lengths
1511+
if len(lhs.type.types) != len(rhs.type.types):
1512+
self.add(Assign(result, self.false() if equal else self.true(), line))
1513+
return result
15101514
# empty tuples
15111515
if len(lhs.type.types) == 0 and len(rhs.type.types) == 0:
15121516
self.add(Assign(result, self.true() if equal else self.false(), line))

mypyc/test-data/run-tuples.test

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,22 @@ def f7(x: List[Tuple[int, int]]) -> int:
203203
def test_unbox_tuple() -> None:
204204
assert f7([(5, 6)]) == 11
205205

206+
def test_comparison() -> None:
207+
assert ('x','y') == ('x','y')
208+
assert not(('x','y') != ('x','y'))
209+
210+
assert ('x','y') != ('x','y',1)
211+
assert not(('x','y') == ('x','y',1))
212+
213+
assert ('x','y',1) != ('x','y')
214+
assert not(('x','y',1) == ('x','y'))
215+
216+
assert ('x','y') != ()
217+
assert not(('x','y') == ())
218+
219+
assert () != ('x','y')
220+
assert not(() == ('x','y'))
221+
206222
# Test that order is irrelevant to unions. Really I only care that this builds.
207223

208224
class A:

0 commit comments

Comments
 (0)