Skip to content

Commit d00cf4f

Browse files
Merge branch 'master' into f-string-folding
2 parents 02882fe + 1b8841b commit d00cf4f

File tree

9 files changed

+17
-22
lines changed

9 files changed

+17
-22
lines changed

mypy/main.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,11 +1066,7 @@ def add_invertible_flag(
10661066
incremental_group.add_argument(
10671067
"--fixed-format-cache",
10681068
action="store_true",
1069-
help=(
1070-
"Use experimental fast and compact fixed format cache"
1071-
if compilation_status == "yes"
1072-
else argparse.SUPPRESS
1073-
),
1069+
help="Use new fast and compact fixed format cache",
10741070
)
10751071
incremental_group.add_argument(
10761072
"--skip-version-check",

mypy/modulefinder.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,7 @@ def default_lib_path(
796796
custom_typeshed_dir = os.path.abspath(custom_typeshed_dir)
797797
typeshed_dir = os.path.join(custom_typeshed_dir, "stdlib")
798798
mypy_extensions_dir = os.path.join(custom_typeshed_dir, "stubs", "mypy-extensions")
799-
mypy_native_dir = os.path.join(custom_typeshed_dir, "stubs", "mypy-native")
799+
librt_dir = os.path.join(custom_typeshed_dir, "stubs", "librt")
800800
versions_file = os.path.join(typeshed_dir, "VERSIONS")
801801
if not os.path.isdir(typeshed_dir) or not os.path.isfile(versions_file):
802802
print(
@@ -812,13 +812,13 @@ def default_lib_path(
812812
data_dir = auto
813813
typeshed_dir = os.path.join(data_dir, "typeshed", "stdlib")
814814
mypy_extensions_dir = os.path.join(data_dir, "typeshed", "stubs", "mypy-extensions")
815-
mypy_native_dir = os.path.join(data_dir, "typeshed", "stubs", "mypy-native")
815+
librt_dir = os.path.join(data_dir, "typeshed", "stubs", "librt")
816816
path.append(typeshed_dir)
817817

818-
# Get mypy-extensions and mypy-native stubs from typeshed, since we treat them as
818+
# Get mypy-extensions and librt stubs from typeshed, since we treat them as
819819
# "internal" libraries, similar to typing and typing-extensions.
820820
path.append(mypy_extensions_dir)
821-
path.append(mypy_native_dir)
821+
path.append(librt_dir)
822822

823823
# Add fallback path that can be used if we have a broken installation.
824824
if sys.platform != "win32":
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
version = "0.1.*"
File renamed without changes.

mypy/typeshed/stubs/mypy-native/METADATA.toml

Lines changed: 0 additions & 1 deletion
This file was deleted.

mypyc/irbuild/builder.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
TypeAlias,
4141
TypeInfo,
4242
TypeParam,
43-
UnaryExpr,
4443
Var,
4544
)
4645
from mypy.types import (
@@ -106,6 +105,7 @@
106105
object_rprimitive,
107106
str_rprimitive,
108107
)
108+
from mypyc.irbuild.constant_fold import constant_fold_expr
109109
from mypyc.irbuild.context import FuncInfo, ImplicitClass
110110
from mypyc.irbuild.ll_builder import LowLevelIRBuilder
111111
from mypyc.irbuild.mapper import Mapper
@@ -965,12 +965,8 @@ def maybe_spill_assignable(self, value: Value) -> Register | AssignmentTarget:
965965
return reg
966966

967967
def extract_int(self, e: Expression) -> int | None:
968-
if isinstance(e, IntExpr):
969-
return e.value
970-
elif isinstance(e, UnaryExpr) and e.op == "-" and isinstance(e.expr, IntExpr):
971-
return -e.expr.value
972-
else:
973-
return None
968+
folded = constant_fold_expr(self, e)
969+
return folded if isinstance(folded, int) else None
974970

975971
def get_sequence_type(self, expr: Expression) -> RType:
976972
return self.get_sequence_type_from_type(self.types[expr])

mypyc/irbuild/constant_fold.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
from __future__ import annotations
1212

13-
from typing import Final, Union, overload
13+
from typing import TYPE_CHECKING, Final, Union, overload
1414

1515
from mypy.checkexpr import try_getting_literal
1616
from mypy.constant_fold import constant_fold_binary_op, constant_fold_unary_op
@@ -34,6 +34,9 @@
3434
from mypyc.irbuild.builder import IRBuilder
3535
from mypyc.irbuild.util import bytes_from_str
3636

37+
if TYPE_CHECKING:
38+
from mypyc.irbuild.builder import IRBuilder
39+
3740
# All possible result types of constant folding
3841
ConstantValue = Union[int, float, complex, str, bytes]
3942
CONST_TYPES: Final = (int, float, complex, str, bytes)

mypyc/irbuild/specialize.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
from mypy.nodes import (
2020
ARG_NAMED,
2121
ARG_POS,
22-
BytesExpr,
2322
CallExpr,
2423
DictExpr,
2524
Expression,
@@ -1057,9 +1056,9 @@ def translate_float(builder: IRBuilder, expr: CallExpr, callee: RefExpr) -> Valu
10571056
def translate_ord(builder: IRBuilder, expr: CallExpr, callee: RefExpr) -> Value | None:
10581057
if len(expr.args) != 1 or expr.arg_kinds[0] != ARG_POS:
10591058
return None
1060-
arg = expr.args[0]
1061-
if isinstance(arg, (StrExpr, BytesExpr)) and len(arg.value) == 1:
1062-
return Integer(ord(arg.value))
1059+
arg = constant_fold_expr(builder, expr.args[0])
1060+
if isinstance(arg, (str, bytes)) and len(arg) == 1:
1061+
return Integer(ord(arg))
10631062
return None
10641063

10651064

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ dependencies = [
5454
"mypy_extensions>=1.0.0",
5555
"pathspec>=0.9.0",
5656
"tomli>=1.1.0; python_version<'3.11'",
57+
"librt>=0.1.0",
5758
]
5859
dynamic = ["version"]
5960

0 commit comments

Comments
 (0)