Skip to content

Commit ca61ff5

Browse files
authored
Merge pull request #50 from python-project-templates/fix-ruff-runtime-annotations
Preserve runtime typing under Ruff rules
2 parents 726e82a + ef6aa7d commit ca61ff5

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

hatch_build/tests/test_cli_model.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from enum import Enum
33
from io import StringIO
44
from pathlib import Path
5-
from typing import Literal
5+
from typing import Literal, Optional, Union
66
from unittest.mock import patch
77

88
from p2a.model import _initlog
@@ -11,6 +11,9 @@
1111
from hatch_build import __version__
1212
from hatch_build.cli import hatchling, parse_extra_args_model
1313

14+
RuntimeOptional = Optional
15+
RuntimeUnion = Union
16+
1417

1518
class MyEnum(Enum):
1619
OPTION_A = "option_a"
@@ -28,7 +31,7 @@ class SubModel(BaseModel, validate_assignment=True):
2831
class 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

Comments
 (0)