Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit582e455

Browse files
authored
Merge branch 'master' into newfeature
2 parentsbb2b468 +284ba55 commit582e455

26 files changed

+232
-95
lines changed

‎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.6.2
7+
librt>=0.6.2; platform_python_implementation != 'PyPy'

‎mypy/checkpattern.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
Type,
4747
TypedDictType,
4848
TypeOfAny,
49+
TypeType,
4950
TypeVarTupleType,
5051
TypeVarType,
5152
UninhabitedType,
@@ -556,6 +557,8 @@ def visit_class_pattern(self, o: ClassPattern) -> PatternType:
556557
fallback=self.chk.named_type("builtins.function")
557558
any_type=AnyType(TypeOfAny.unannotated)
558559
typ=callable_with_ellipsis(any_type,ret_type=any_type,fallback=fallback)
560+
elifisinstance(p_typ,TypeType)andisinstance(p_typ.item,NoneType):
561+
typ=p_typ.item
559562
elifnotisinstance(p_typ,AnyType):
560563
self.msg.fail(
561564
message_registry.CLASS_PATTERN_TYPE_REQUIRED.format(

‎mypy/main.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,10 @@ def add_invertible_flag(
815815
add_invertible_flag(
816816
"--force-union-syntax",default=False,help=argparse.SUPPRESS,group=none_group
817817
)
818+
# For internal use only! Will be removed once Mypy drops support for Python 3.9.
819+
add_invertible_flag(
820+
"--overwrite-union-syntax",default=False,help=argparse.SUPPRESS,group=none_group
821+
)
818822

819823
lint_group=parser.add_argument_group(
820824
title="Configuring warnings",

‎mypy/options.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,8 @@ def __init__(self) -> None:
413413
# Deprecated, Mypy only supports Python 3.9+
414414
self.force_uppercase_builtins=False
415415
self.force_union_syntax=False
416+
# Mypy internal use only! Set during test run.
417+
self.overwrite_union_syntax=False
416418

417419
# Sets custom output format
418420
self.output:str|None=None
@@ -434,7 +436,7 @@ def use_lowercase_names(self) -> bool:
434436
defuse_or_syntax(self)->bool:
435437
ifself.python_version>= (3,10):
436438
returnnotself.force_union_syntax
437-
returnFalse
439+
returnself.overwrite_union_syntax
438440

439441
defuse_star_unpack(self)->bool:
440442
returnself.python_version>= (3,11)

‎mypy/test/testcmdline.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,13 @@ def test_python_cmdline(testcase: DataDrivenTestCase, step: int) -> None:
6060
args=parse_args(testcase.input[0])
6161
custom_cwd=parse_cwd(testcase.input[1])iflen(testcase.input)>1elseNone
6262
args.append("--show-traceback")
63+
args.append("--overwrite-union-syntax")
6364
if"--error-summary"notinargs:
6465
args.append("--no-error-summary")
6566
if"--show-error-codes"notinargs:
6667
args.append("--hide-error-codes")
6768
if"--disallow-empty-bodies"notinargs:
6869
args.append("--allow-empty-bodies")
69-
if"--no-force-union-syntax"notinargs:
70-
args.append("--force-union-syntax")
7170
# Type check the program.
7271
fixed= [python3_path,"-m","mypy"]
7372
env=os.environ.copy()

‎mypy/test/testpythoneval.py‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ def test_python_evaluation(testcase: DataDrivenTestCase, cache_dir: str) -> None
5252
"--no-error-summary",
5353
"--hide-error-codes",
5454
"--allow-empty-bodies",
55+
"--overwrite-union-syntax",
5556
"--test-env",# Speeds up some checks
5657
]
5758
interpreter=python3_path
@@ -71,9 +72,6 @@ def test_python_evaluation(testcase: DataDrivenTestCase, cache_dir: str) -> None
7172
return
7273
mypy_cmdline.extend(additional_flags)
7374

74-
if"--no-force-union-syntax"notinmypy_cmdline:
75-
mypy_cmdline.append("--force-union-syntax")
76-
7775
# Write the program to a file.
7876
program="_"+testcase.name+".py"
7977
program_path=os.path.join(test_temp_dir,program)

‎mypy/types.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3736,6 +3736,7 @@ class TypeStrVisitor(SyntheticTypeVisitor[str]):
37363736
Notes:
37373737
- Represent unbound types as Foo? or Foo?[...].
37383738
- Represent the NoneType type as None.
3739+
- Represent Union[x, y] as x | y
37393740
"""
37403741

37413742
def__init__(self,id_mapper:IdMapper|None=None,*,options:Options)->None:

‎mypyc/ir/deps.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,4 @@ def get_header(self) -> str:
5050
LIBRT_BASE64:Final=Capsule("librt.base64")
5151

5252
BYTES_EXTRA_OPS:Final=SourceDep("bytes_extra_ops.c")
53+
BYTES_WRITER_EXTRA_OPS:Final=SourceDep("byteswriter_extra_ops.c")

‎mypyc/irbuild/builder.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -990,8 +990,10 @@ def get_sequence_type_from_type(self, target_type: Type) -> RType:
990990
elifisinstance(target_type,TypeVarLikeType):
991991
returnself.get_sequence_type_from_type(target_type.upper_bound)
992992
elifisinstance(target_type,TupleType):
993+
items=target_type.items
994+
assertitems,"This function does not support empty tuples"
993995
# Tuple might have elements of different types.
994-
rtypes={self.mapper.type_to_rtype(item)foritemintarget_type.items}
996+
rtypes=set(map(self.mapper.type_to_rtype,items))
995997
iflen(rtypes)==1:
996998
returnrtypes.pop()
997999
else:

‎mypyc/irbuild/for_helpers.py‎

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from __future__importannotations
99

1010
fromcollections.abcimportCallable
11-
fromtypingimportClassVar
11+
fromtypingimportClassVar,cast
1212

1313
frommypy.nodesimport (
1414
ARG_POS,
@@ -242,25 +242,45 @@ def sequence_from_generator_preallocate_helper(
242242
rtype=builder.node_type(sequence_expr)
243243
ifnot (is_sequence_rprimitive(rtype)orisinstance(rtype,RTuple)):
244244
returnNone
245-
sequence=builder.accept(sequence_expr)
246-
length=get_expr_length_value(builder,sequence_expr,sequence,line,use_pyssize_t=True)
245+
247246
ifisinstance(rtype,RTuple):
248247
# If input is RTuple, box it to tuple_rprimitive for generic iteration
249248
# TODO: this can be optimized a bit better with an unrolled ForRTuple helper
250249
proper_type=get_proper_type(builder.types[sequence_expr])
251250
assertisinstance(proper_type,TupleType),proper_type
252251

253-
get_item_ops= [
254-
(
255-
LoadLiteral(typ.value,object_rprimitive)
256-
ifisinstance(typ,LiteralType)
257-
elseTupleGet(sequence,i,line)
258-
)
259-
fori,typinenumerate(get_proper_types(proper_type.items))
260-
]
252+
# the for_loop_helper_with_index crashes for empty tuples, bail out
253+
ifnotproper_type.items:
254+
returnNone
255+
256+
proper_types=get_proper_types(proper_type.items)
257+
258+
get_item_ops:list[LoadLiteral|TupleGet]
259+
ifall(isinstance(typ,LiteralType)fortypinproper_types):
260+
get_item_ops= [
261+
LoadLiteral(cast(LiteralType,typ).value,object_rprimitive)
262+
fortypinproper_types
263+
]
264+
265+
else:
266+
sequence=builder.accept(sequence_expr)
267+
get_item_ops= [
268+
(
269+
LoadLiteral(typ.value,object_rprimitive)
270+
ifisinstance(typ,LiteralType)
271+
elseTupleGet(sequence,i,line)
272+
)
273+
fori,typinenumerate(proper_types)
274+
]
275+
261276
items=list(map(builder.add,get_item_ops))
262277
sequence=builder.new_tuple(items,line)
263278

279+
else:
280+
sequence=builder.accept(sequence_expr)
281+
282+
length=get_expr_length_value(builder,sequence_expr,sequence,line,use_pyssize_t=True)
283+
264284
target_op=empty_op_llbuilder(length,line)
265285

266286
defset_item(item_index:Value)->None:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp