Skip to content

Commit b2d7ce0

Browse files
Remove TYPE_CHECKING protected import cycles (#1314)
* Remove `TYPE_CHECKING` protected import cycles * Fix un-exported import references
1 parent e45cb67 commit b2d7ce0

7 files changed

Lines changed: 59 additions & 52 deletions

File tree

src/usethis/_file/yaml/io_.py

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -37,47 +37,12 @@
3737
from collections.abc import Generator, Sequence
3838
from io import TextIOWrapper
3939
from pathlib import Path
40-
from types import NoneType
41-
from typing import TypeAlias
42-
43-
from ruamel.yaml.comments import (
44-
CommentedOrderedMap,
45-
CommentedSeq,
46-
CommentedSet,
47-
TaggedScalar,
48-
)
49-
from ruamel.yaml.scalarbool import ScalarBoolean
50-
from ruamel.yaml.scalarfloat import ScalarFloat
51-
from ruamel.yaml.scalarint import BinaryInt, HexCapsInt, HexInt, OctalInt, ScalarInt
52-
from ruamel.yaml.scalarstring import FoldedScalarString, LiteralScalarString
53-
from ruamel.yaml.timestamp import TimeStamp
40+
5441
from typing_extensions import Self
5542

43+
from usethis._file.yaml.typing_ import YAMLLiteral
5644
from usethis._io import Key
5745

58-
YAMLLiteral: TypeAlias = (
59-
NoneType
60-
| bool
61-
| float
62-
| int
63-
| str
64-
| BinaryInt
65-
| FoldedScalarString
66-
| HexInt
67-
| HexCapsInt
68-
| LiteralScalarString
69-
| OctalInt
70-
| ScalarBoolean
71-
| ScalarFloat
72-
| ScalarInt
73-
| TaggedScalar
74-
| TimeStamp
75-
| CommentedSeq
76-
| CommentedSet
77-
| CommentedOrderedMap
78-
| CommentedMap
79-
)
80-
8146

8247
class YAMLFileManager(KeyValueFileManager):
8348
"""An abstract class for managing YAML files."""

src/usethis/_file/yaml/typing_.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from types import NoneType
2+
from typing import TypeAlias
3+
4+
from ruamel.yaml.comments import (
5+
CommentedMap,
6+
CommentedOrderedMap,
7+
CommentedSeq,
8+
CommentedSet,
9+
TaggedScalar,
10+
)
11+
from ruamel.yaml.scalarbool import ScalarBoolean
12+
from ruamel.yaml.scalarfloat import ScalarFloat
13+
from ruamel.yaml.scalarint import BinaryInt, HexCapsInt, HexInt, OctalInt, ScalarInt
14+
from ruamel.yaml.scalarstring import FoldedScalarString, LiteralScalarString
15+
from ruamel.yaml.timestamp import TimeStamp
16+
17+
YAMLLiteral: TypeAlias = (
18+
NoneType
19+
| bool
20+
| float
21+
| int
22+
| str
23+
| BinaryInt
24+
| FoldedScalarString
25+
| HexInt
26+
| HexCapsInt
27+
| LiteralScalarString
28+
| OctalInt
29+
| ScalarBoolean
30+
| ScalarFloat
31+
| ScalarInt
32+
| TaggedScalar
33+
| TimeStamp
34+
| CommentedSeq
35+
| CommentedSet
36+
| CommentedOrderedMap
37+
| CommentedMap
38+
)

src/usethis/_file/yaml/update.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
if TYPE_CHECKING:
1111
from typing import Any
1212

13-
from usethis._file.yaml.io_ import YAMLLiteral
13+
from usethis._file.yaml.typing_ import YAMLLiteral
1414

1515

1616
def update_ruamel_yaml_map(

src/usethis/_integrations/ci/bitbucket/yaml.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
if TYPE_CHECKING:
1515
from pydantic import BaseModel
1616

17-
from usethis._integrations.pydantic.dump import ModelRepresentation
17+
from usethis._integrations.pydantic.typing_ import ModelRepresentation
18+
1819

1920
ORDER_BY_CLS: dict[type[BaseModel], list[str]] = {
2021
schema.PipelinesConfiguration: ["image", "clone", "definitions"],

src/usethis/_integrations/pre_commit/yaml.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
if TYPE_CHECKING:
1616
from pydantic import BaseModel
1717

18-
from usethis._integrations.pydantic.dump import ModelRepresentation
18+
from usethis._integrations.pydantic.typing_ import ModelRepresentation
1919

2020
ORDER_BY_CLS: dict[type[BaseModel], list[str]] = {}
2121

src/usethis/_integrations/pydantic/dump.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,7 @@
77
from pydantic import BaseModel, RootModel
88

99
if TYPE_CHECKING:
10-
from typing import TypeAlias
11-
12-
from usethis._file.yaml.io_ import YAMLLiteral
13-
14-
ModelLiteral: TypeAlias = bool | int | float | str
15-
ModelRepresentation: TypeAlias = (
16-
ModelLiteral
17-
| dict[str, "ModelRepresentation"]
18-
| list["ModelRepresentation"]
19-
| BaseModel
20-
| YAMLLiteral
21-
)
10+
from usethis._integrations.pydantic.typing_ import ModelLiteral, ModelRepresentation
2211

2312

2413
class _FillValue:
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from typing import TypeAlias
2+
3+
from pydantic import BaseModel
4+
5+
from usethis._file.yaml.typing_ import YAMLLiteral
6+
7+
ModelLiteral: TypeAlias = bool | int | float | str
8+
ModelRepresentation: TypeAlias = (
9+
ModelLiteral
10+
| dict[str, "ModelRepresentation"]
11+
| list["ModelRepresentation"]
12+
| BaseModel
13+
| YAMLLiteral
14+
)

0 commit comments

Comments
 (0)