@@ -646,7 +646,16 @@ def test_class_path_union_mixture_dataclass_and_class(parser, union_type):
646646 class DataClassWithAliasType :
647647 p1 : IntOrString # type: ignore[valid-type]
648648
649- def test_bare_alias_type (parser ):
649+ if annotated :
650+
651+ @dataclasses .dataclass
652+ class DataClassWithAnnotatedAliasType :
653+ p1 : annotated [IntOrString , 1 ] # type: ignore[valid-type]
654+
655+
656+ @pytest .mark .skipif (not type_alias_type , reason = "TypeAliasType is required" )
657+ class TestTypeAliasType :
658+ def test_bare_alias_type (self , parser ):
650659 parser .add_argument ("--data" , type = IntOrString )
651660 help_str = get_parser_help (parser )
652661 help_str_lines = [line for line in help_str .split ("\n " ) if "type: IntOrString" in line ]
@@ -657,7 +666,7 @@ def test_bare_alias_type(parser):
657666 cfg = parser .parse_args (["--data=3" ])
658667 assert cfg .data == 3
659668
660- def test_dataclass_with_alias_type (parser ):
669+ def test_dataclass_with_alias_type (self , parser ):
661670 parser .add_argument ("--data" , type = DataClassWithAliasType )
662671 help_str = get_parser_help (parser )
663672 help_str_lines = [line for line in help_str .split ("\n " ) if "type: IntOrString" in line ]
@@ -669,7 +678,7 @@ def test_dataclass_with_alias_type(parser):
669678 assert cfg .data .p1 == 3
670679
671680 @pytest .mark .skipif (not annotated , reason = "Annotated is required" )
672- def test_annotated_alias_type (parser ):
681+ def test_annotated_alias_type (self , parser ):
673682 parser .add_argument ("--data" , type = annotated [IntOrString , 1 ])
674683 help_str = get_parser_help (parser )
675684 help_str_lines = [line for line in help_str .split ("\n " ) if "type: Annotated[IntOrString, 1]" in line ]
@@ -680,14 +689,8 @@ def test_annotated_alias_type(parser):
680689 cfg = parser .parse_args (["--data=3" ])
681690 assert cfg .data == 3
682691
683- if annotated :
684-
685- @dataclasses .dataclass
686- class DataClassWithAnnotatedAliasType :
687- p1 : annotated [IntOrString , 1 ] # type: ignore[valid-type]
688-
689692 @pytest .mark .skipif (not annotated , reason = "Annotated is required" )
690- def test_dataclass_with_annotated_alias_type (parser ):
693+ def test_dataclass_with_annotated_alias_type (self , parser ):
691694 parser .add_argument ("--data" , type = DataClassWithAnnotatedAliasType )
692695 help_str = get_parser_help (parser )
693696 # The printable field datatype is not uniform across versions.
0 commit comments