Skip to content

Commit 0ae6611

Browse files
Merge branch 'master' into constant-fold-convert-format
2 parents 3ebbee5 + 6aa44da commit 0ae6611

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+473
-258
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ repos:
4141
# actionlint has a shellcheck integration which extracts shell scripts in `run:` steps from GitHub Actions
4242
# and checks these with shellcheck. This is arguably its most useful feature,
4343
# but the integration only works if shellcheck is installed
44-
- "github.com/wasilibs/go-shellcheck/cmd/shellcheck@v0.10.0"
44+
- "github.com/wasilibs/go-shellcheck/cmd/shellcheck@v0.11.0"
4545
- repo: https://github.com/woodruffw/zizmor-pre-commit
4646
rev: v1.5.2
4747
hooks:

mypy-requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ typing_extensions>=4.6.0
44
mypy_extensions>=1.0.0
55
pathspec>=0.9.0
66
tomli>=1.1.0; python_version<'3.11'
7-
librt>=0.1.0
7+
librt>=0.2.1

mypy/cache.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
from collections.abc import Sequence
44
from typing import Final
55

6-
from mypy_extensions import u8
7-
from native_internal import (
6+
from librt.internal import (
87
Buffer as Buffer,
98
read_bool as read_bool,
109
read_float as read_float,
@@ -17,6 +16,7 @@
1716
write_str as write_str,
1817
write_tag as write_tag,
1918
)
19+
from mypy_extensions import u8
2020

2121
# Always use this type alias to refer to type tags.
2222
Tag = u8

mypy/checkpattern.py

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from mypy.maptype import map_instance_to_supertype
1515
from mypy.meet import narrow_declared_type
1616
from mypy.messages import MessageBuilder
17-
from mypy.nodes import ARG_POS, Context, Expression, NameExpr, TypeAlias, TypeInfo, Var
17+
from mypy.nodes import ARG_POS, Context, Expression, NameExpr, TypeAlias, Var
1818
from mypy.options import Options
1919
from mypy.patterns import (
2020
AsPattern,
@@ -37,6 +37,7 @@
3737
)
3838
from mypy.types import (
3939
AnyType,
40+
FunctionLike,
4041
Instance,
4142
LiteralType,
4243
NoneType,
@@ -538,27 +539,20 @@ def visit_class_pattern(self, o: ClassPattern) -> PatternType:
538539
# Check class type
539540
#
540541
type_info = o.class_ref.node
541-
if type_info is None:
542-
typ: Type = AnyType(TypeOfAny.from_error)
543-
elif isinstance(type_info, TypeAlias) and not type_info.no_args:
542+
typ = self.chk.expr_checker.accept(o.class_ref)
543+
p_typ = get_proper_type(typ)
544+
if isinstance(type_info, TypeAlias) and not type_info.no_args:
544545
self.msg.fail(message_registry.CLASS_PATTERN_GENERIC_TYPE_ALIAS, o)
545546
return self.early_non_match()
546-
elif isinstance(type_info, TypeInfo):
547-
typ = fill_typevars_with_any(type_info)
548-
elif isinstance(type_info, TypeAlias):
549-
typ = type_info.target
550-
elif (
551-
isinstance(type_info, Var)
552-
and type_info.type is not None
553-
and isinstance(get_proper_type(type_info.type), AnyType)
554-
):
555-
typ = type_info.type
556-
else:
557-
if isinstance(type_info, Var) and type_info.type is not None:
558-
name = type_info.type.str_with_options(self.options)
559-
else:
560-
name = type_info.name
561-
self.msg.fail(message_registry.CLASS_PATTERN_TYPE_REQUIRED.format(name), o)
547+
elif isinstance(p_typ, FunctionLike) and p_typ.is_type_obj():
548+
typ = fill_typevars_with_any(p_typ.type_object())
549+
elif not isinstance(p_typ, AnyType):
550+
self.msg.fail(
551+
message_registry.CLASS_PATTERN_TYPE_REQUIRED.format(
552+
typ.str_with_options(self.options)
553+
),
554+
o,
555+
)
562556
return self.early_non_match()
563557

564558
new_type, rest_type = self.chk.conditional_types_with_intersection(
@@ -697,6 +691,8 @@ def should_self_match(self, typ: Type) -> bool:
697691
typ = get_proper_type(typ)
698692
if isinstance(typ, TupleType):
699693
typ = typ.partial_fallback
694+
if isinstance(typ, AnyType):
695+
return False
700696
if isinstance(typ, Instance) and typ.type.get("__match_args__") is not None:
701697
# Named tuples and other subtypes of builtins that define __match_args__
702698
# should not self match.

mypy/errors.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -806,8 +806,8 @@ def generate_unused_ignore_errors(self, file: str) -> None:
806806
continue
807807
if codes.UNUSED_IGNORE.code in ignored_codes:
808808
continue
809-
used_ignored_codes = used_ignored_lines[line]
810-
unused_ignored_codes = set(ignored_codes) - set(used_ignored_codes)
809+
used_ignored_codes = set(used_ignored_lines[line])
810+
unused_ignored_codes = [c for c in ignored_codes if c not in used_ignored_codes]
811811
# `ignore` is used
812812
if not ignored_codes and used_ignored_codes:
813813
continue
@@ -817,7 +817,7 @@ def generate_unused_ignore_errors(self, file: str) -> None:
817817
# Display detail only when `ignore[...]` specifies more than one error code
818818
unused_codes_message = ""
819819
if len(ignored_codes) > 1 and unused_ignored_codes:
820-
unused_codes_message = f"[{', '.join(sorted(unused_ignored_codes))}]"
820+
unused_codes_message = f"[{', '.join(unused_ignored_codes)}]"
821821
message = f'Unused "type: ignore{unused_codes_message}" comment'
822822
for unused in unused_ignored_codes:
823823
narrower = set(used_ignored_codes) & codes.sub_code_map[unused]

mypy/fastparse.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,12 @@ def parse(
232232
assert options.python_version[0] >= 3
233233
feature_version = options.python_version[1]
234234
try:
235-
# Disable deprecation warnings about \u
235+
# Disable
236+
# - deprecation warnings for 'invalid escape sequence' (Python 3.11 and below)
237+
# - syntax warnings for 'invalid escape sequence' (3.12+) and 'return in finally' (3.14+)
236238
with warnings.catch_warnings():
237239
warnings.filterwarnings("ignore", category=DeprecationWarning)
240+
warnings.filterwarnings("ignore", category=SyntaxWarning)
238241
ast = ast3_parse(source, fnam, "exec", feature_version=feature_version)
239242

240243
tree = ASTConverter(

mypy/meet.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,9 @@ def narrow_declared_type(declared: Type, narrowed: Type) -> Type:
170170
):
171171
# We put this branch early to get T(bound=Union[A, B]) instead of
172172
# Union[T(bound=A), T(bound=B)] that will be confusing for users.
173-
return declared.copy_modified(upper_bound=original_narrowed)
173+
return declared.copy_modified(
174+
upper_bound=narrow_declared_type(declared.upper_bound, original_narrowed)
175+
)
174176
elif not is_overlapping_types(declared, narrowed, prohibit_none_typevar_overlap=True):
175177
if state.strict_optional:
176178
return UninhabitedType()

mypy/semanal.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1791,11 +1791,10 @@ def push_type_args(
17911791
return None
17921792
tvs.append((p.name, tv))
17931793

1794-
for name, tv in tvs:
1795-
if self.is_defined_type_param(name):
1796-
self.fail(f'"{name}" already defined as a type parameter', context)
1794+
if self.is_defined_type_param(p.name):
1795+
self.fail(f'"{p.name}" already defined as a type parameter', context)
17971796
else:
1798-
self.add_symbol(name, tv, context, no_progress=True, type_param=True)
1797+
self.add_symbol(p.name, tv, context, no_progress=True, type_param=True)
17991798

18001799
return tvs
18011800

mypy/stubgenc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ def add_args(
322322
default_value = get_default_value(i, arg)
323323
if default_value is not _Missing.VALUE:
324324
if arg in annotations:
325-
argtype = annotations[arg]
325+
argtype = get_annotation(arg)
326326
else:
327327
argtype = self.get_type_annotation(default_value)
328328
if argtype == "None":

mypy/test/teststubtest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ class _TypedDict(Mapping[str, object]):
8888
__total__: ClassVar[bool]
8989
__readonly_keys__: ClassVar[frozenset[str]]
9090
__mutable_keys__: ClassVar[frozenset[str]]
91+
__closed__: ClassVar[bool | None]
92+
__extra_items__: ClassVar[Any]
9193
def overload(func: _T) -> _T: ...
9294
def type_check_only(func: _T) -> _T: ...
9395
def final(func: _T) -> _T: ...

0 commit comments

Comments
 (0)