Skip to content

Commit a210b72

Browse files
DetachHeadpre-commit-ci[bot]frostming
authored
chore: use Literal type for valid target values (#227)
* use `Literal` type for valid target values * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix missing import * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * remove `TypeAlias` import since it's not needed and doesn't exist on older python versions * use `typeing_extensions.Literal` for python 3.7 * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update src/pdm/backend/base.py --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Frost Ming <mianghong@gmail.com>
1 parent 32e3a33 commit a210b72

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

src/pdm/backend/base.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,15 @@
77
import warnings
88
from fnmatch import fnmatch
99
from pathlib import Path
10-
from typing import TYPE_CHECKING, Any, Iterable, Mapping, TypeVar, cast
10+
from typing import (
11+
TYPE_CHECKING,
12+
Any,
13+
Iterable,
14+
Literal,
15+
Mapping,
16+
TypeVar,
17+
cast,
18+
)
1119

1220
from pdm.backend.config import Config
1321
from pdm.backend.exceptions import PDMWarning, ValidationError
@@ -81,12 +89,15 @@ def _find_top_packages(root: str) -> list[str]:
8189
return result
8290

8391

92+
Target = Literal["sdist", "wheel", "editable"]
93+
94+
8495
class Builder:
8596
"""Base class for building and distributing a package from given path."""
8697

8798
DEFAULT_EXCLUDES = [".pdm-build"]
8899

89-
target: str
100+
target: Target
90101
hooks: list[BuildHookInterface] = [DynamicVersionBuildHook()]
91102

92103
def __init__(

src/pdm/backend/hooks/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
if TYPE_CHECKING:
1010
from typing import Protocol
1111

12-
from pdm.backend.base import Builder
12+
from pdm.backend.base import Builder, Target
1313
else:
1414
Protocol = object
1515

@@ -44,7 +44,7 @@ def root(self) -> Path:
4444
return self.builder.location
4545

4646
@property
47-
def target(self) -> str:
47+
def target(self) -> Target:
4848
"""The target to build, one of 'sdist', 'wheel', 'editable'"""
4949
return self.builder.target
5050

0 commit comments

Comments
 (0)