Skip to content

Commit 41e59ac

Browse files
Merge branch 'master' into fix_match_callable
2 parents df67812 + 04a586c commit 41e59ac

37 files changed

+422
-255
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,
@@ -539,21 +540,13 @@ def visit_class_pattern(self, o: ClassPattern) -> PatternType:
539540
# Check class type
540541
#
541542
type_info = o.class_ref.node
542-
if type_info is None:
543-
typ: Type = AnyType(TypeOfAny.from_error)
544-
elif isinstance(type_info, TypeAlias) and not type_info.no_args:
543+
typ = self.chk.expr_checker.accept(o.class_ref)
544+
p_typ = get_proper_type(typ)
545+
if isinstance(type_info, TypeAlias) and not type_info.no_args:
545546
self.msg.fail(message_registry.CLASS_PATTERN_GENERIC_TYPE_ALIAS, o)
546547
return self.early_non_match()
547-
elif isinstance(type_info, TypeInfo):
548-
typ = fill_typevars_with_any(type_info)
549-
elif isinstance(type_info, TypeAlias):
550-
typ = type_info.target
551-
elif (
552-
isinstance(type_info, Var)
553-
and type_info.type is not None
554-
and isinstance(get_proper_type(type_info.type), AnyType)
555-
):
556-
typ = type_info.type
548+
elif isinstance(p_typ, FunctionLike) and p_typ.is_type_obj():
549+
typ = fill_typevars_with_any(p_typ.type_object())
557550
elif (
558551
isinstance(type_info, Var)
559552
and type_info.type is not None
@@ -563,12 +556,13 @@ def visit_class_pattern(self, o: ClassPattern) -> PatternType:
563556
fallback = self.chk.named_type("builtins.function")
564557
any_type = AnyType(TypeOfAny.unannotated)
565558
typ = callable_with_ellipsis(any_type, ret_type=any_type, fallback=fallback)
566-
else:
567-
if isinstance(type_info, Var) and type_info.type is not None:
568-
name = type_info.type.str_with_options(self.options)
569-
else:
570-
name = type_info.name
571-
self.msg.fail(message_registry.CLASS_PATTERN_TYPE_REQUIRED.format(name), o)
559+
elif not isinstance(p_typ, AnyType):
560+
self.msg.fail(
561+
message_registry.CLASS_PATTERN_TYPE_REQUIRED.format(
562+
typ.str_with_options(self.options)
563+
),
564+
o,
565+
)
572566
return self.early_non_match()
573567

574568
new_type, rest_type = self.chk.conditional_types_with_intersection(
@@ -707,6 +701,8 @@ def should_self_match(self, typ: Type) -> bool:
707701
typ = get_proper_type(typ)
708702
if isinstance(typ, TupleType):
709703
typ = typ.partial_fallback
704+
if isinstance(typ, AnyType):
705+
return False
710706
if isinstance(typ, Instance) and typ.type.get("__match_args__") is not None:
711707
# Named tuples and other subtypes of builtins that define __match_args__
712708
# 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/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: ...
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version = "0.1.*"
1+
version = "0.2.*"

0 commit comments

Comments
 (0)