22from enum import Enum
33from io import StringIO
44from pathlib import Path
5- from typing import Literal
5+ from typing import Literal , Optional , Union
66from unittest .mock import patch
77
88from p2a .model import _initlog
1111from hatch_build import __version__
1212from hatch_build .cli import hatchling , parse_extra_args_model
1313
14+ RuntimeOptional = Optional
15+ RuntimeUnion = Union
16+
1417
1518class MyEnum (Enum ):
1619 OPTION_A = "option_a"
@@ -28,7 +31,7 @@ class SubModel(BaseModel, validate_assignment=True):
2831class MyTopLevelModel (BaseModel , validate_assignment = True ):
2932 extra_arg : bool = False
3033 extra_arg_with_value : str = "default"
31- extra_arg_with_value_equals : str | None = "default_equals"
34+ extra_arg_with_value_equals : RuntimeOptional [ str ] = "default_equals"
3235 extra_arg_literal : Literal ["a" , "b" , "c" ] = "a"
3336
3437 enum_arg : MyEnum = MyEnum .OPTION_A
@@ -48,15 +51,15 @@ class MyTopLevelModel(BaseModel, validate_assignment=True):
4851
4952 submodel : SubModel
5053 submodel2 : SubModel = SubModel (sub_args = 84 , sub_arg_with_value = "predefined" , sub_arg_enum = MyEnum .OPTION_B , sub_arg_literal = "z" )
51- submodel3 : SubModel | None = None
54+ submodel3 : RuntimeOptional [ SubModel ] = None
5255
5356 submodel_list_instanced : list [SubModel ] = [SubModel ()]
5457 submodel_dict_instanced : dict [str , SubModel ] = {"a" : SubModel ()}
5558
5659 unsupported_literal : Literal [b"test" ] = b"test"
5760 unsupported_dict : dict [SubModel , str ] = {}
58- unsupported_dict_mixed_types : dict [str , str | SubModel ] = {}
59- unsupported_random_type : set | None = None
61+ unsupported_dict_mixed_types : dict [str , RuntimeUnion [ str , SubModel ] ] = {}
62+ unsupported_random_type : RuntimeOptional [ set ] = None
6063
6164 unsupported_submodel_list : list [SubModel ] = []
6265 unsupported_submodel_dict : dict [str , SubModel ] = {}
0 commit comments