@@ -326,6 +326,83 @@ def test_handling_format_strings_basic(self):
326326 checker .check_children ("JoinedStr" , ['f"' , "abc" , "FormattedValue" , "" , '"' ])
327327 checker .check_children ("FormattedValue" , ["{" , "" , "Name" , "" , "}" ])
328328
329+ @testutils .only_for_versions_higher ("3.12" )
330+ def test_handling_pep695_type_alias (self ):
331+ source = dedent ("""\
332+ type Alias[T] = list[T]
333+ """ )
334+ ast_frag = patchedast .get_patched_ast (source , True )
335+ checker = _ResultChecker (self , ast_frag )
336+ checker .check_children (
337+ "TypeAlias" ,
338+ ["type" , " " , "Name" , "" , "[" , "" , "TypeVar" , "" , "]" , " = " ,
339+ "Subscript" ],
340+ )
341+
342+ @testutils .only_for_versions_higher ("3.12" )
343+ def test_handling_pep695_generic_function (self ):
344+ # TP occurs only in the type parameter list, so its region can only
345+ # come from the "[TP]" clause rendered between the name and "(".
346+ source = dedent ("""\
347+ def f[TP](x):
348+ return x
349+ """ )
350+ ast_frag = patchedast .get_patched_ast (source , True )
351+ checker = _ResultChecker (self , ast_frag )
352+ checker .check_children (
353+ "FunctionDef" ,
354+ ["def" , " " , "f" , "" , "[" , "" , "TypeVar" , "" , "]" , "" , "(" , "" ,
355+ "arguments" , "" , ")" , "" , ":" , "\n " , "Return" ],
356+ )
357+ start = source .index ("TP" )
358+ checker .check_region ("TypeVar" , start , start + len ("TP" ))
359+
360+ @testutils .only_for_versions_higher ("3.12" )
361+ def test_handling_pep695_generic_class (self ):
362+ source = dedent ("""\
363+ class C[TP]:
364+ pass
365+ """ )
366+ ast_frag = patchedast .get_patched_ast (source , True )
367+ checker = _ResultChecker (self , ast_frag )
368+ checker .check_children (
369+ "ClassDef" ,
370+ ["class" , " " , "C" , "" , "[" , "" , "TypeVar" , "" , "]" , "" , ":" ,
371+ "\n " , "Pass" ],
372+ )
373+ start = source .index ("TP" )
374+ checker .check_region ("TypeVar" , start , start + len ("TP" ))
375+
376+ @testutils .only_for_versions_higher ("3.10" )
377+ def test_handling_match_sequence_and_star (self ):
378+ source = dedent ("""\
379+ match x:
380+ case [1, *rest]:
381+ pass
382+ """ )
383+ ast_frag = patchedast .get_patched_ast (source , True )
384+ checker = _ResultChecker (self , ast_frag )
385+ checker .check_children (
386+ "MatchSequence" ,
387+ ["[" , "" , "MatchValue" , "" , "," , " " , "MatchStar" , "" , "]" ],
388+ )
389+ start = source .index ("[1, *rest]" )
390+ checker .check_region ("MatchSequence" , start , start + len ("[1, *rest]" ))
391+ checker .check_children ("MatchStar" , ["*" , "" , "rest" ])
392+
393+ @testutils .only_for_versions_higher ("3.10" )
394+ def test_handling_match_or_and_singleton (self ):
395+ source = dedent ("""\
396+ match x:
397+ case 1 | None:
398+ pass
399+ """ )
400+ ast_frag = patchedast .get_patched_ast (source , True )
401+ checker = _ResultChecker (self , ast_frag )
402+ checker .check_children (
403+ "MatchOr" , ["MatchValue" , " " , "|" , " " , "MatchSingleton" ]
404+ )
405+
329406 @testutils .only_for_versions_higher ("3.6" )
330407 def test_handling_format_strings_with_implicit_join (self ):
331408 source = '''"1" + rf'abc{a}' f"""xxx{b} """\n '''
0 commit comments