Skip to content

Commit c1a78b3

Browse files
refactor: fix runtime TypeAlias with pipe operator
Move GivenPyProjectResult type alias after PyProjectData class definition to use unquoted modern syntax. TypeAlias with pipe operator requires runtime evaluation, so forward references must be avoided. Changes: - vcs-versioning/src/vcs_versioning/_pyproject_reading.py: - Move GivenPyProjectResult after PyProjectData class - Use unquoted: PyProjectData | InvalidTomlError | FileNotFoundError | None - Fixes TypeError: unsupported operand type(s) for |: 'str' and 'type' - vcs-versioning/src/vcs_versioning/_types.py: - PathT: os.PathLike[str] | str (unquoted) - Already worked since os is imported
1 parent 0a79a96 commit c1a78b3

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

vcs-versioning/src/vcs_versioning/_pyproject_reading.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,6 @@
2626

2727
DEFAULT_PYPROJECT_PATH = Path("pyproject.toml")
2828

29-
# Testing injection type for configuration reading
30-
GivenPyProjectResult: TypeAlias = (
31-
"PyProjectData" | InvalidTomlError | FileNotFoundError | None
32-
)
33-
3429

3530
@dataclass
3631
class PyProjectData:
@@ -161,6 +156,12 @@ def project_version(self) -> str | None:
161156
return self.project.get("version")
162157

163158

159+
# Testing injection type for configuration reading
160+
GivenPyProjectResult: TypeAlias = (
161+
PyProjectData | InvalidTomlError | FileNotFoundError | None
162+
)
163+
164+
164165
def has_build_package(
165166
requires: Sequence[str], canonical_build_package_name: str
166167
) -> bool:

vcs-versioning/src/vcs_versioning/_types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
if TYPE_CHECKING:
88
from . import _version_schemes as version
99

10-
PathT: TypeAlias = "os.PathLike[str]" | str
10+
PathT: TypeAlias = os.PathLike[str] | str
1111

1212
CMD_TYPE: TypeAlias = Sequence[PathT] | str
1313

0 commit comments

Comments
 (0)