Skip to content

Commit 8c23c5b

Browse files
Merge pull request #1286 from effigies/scm_version_sentinel
fix: Use missing-argument sentinel for dump_version argument
2 parents 6a1fc3b + 5f018e9 commit 8c23c5b

3 files changed

Lines changed: 16 additions & 5 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Allow `dump_version()` deprecation warning to be silenced by passing `scm_version=None`.

setuptools-scm/testing_scm/test_functions.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,14 @@ def test_write_version_to_path_deprecation_warning_none(tmp_path: Path) -> None:
125125

126126
target_file = tmp_path / "version.py"
127127

128-
# This should raise a deprecation warning when scm_version=None is explicitly passed
128+
# This should raise a deprecation warning when scm_version=None is not explicitly passed
129129
with pytest.warns(
130130
DeprecationWarning, match="write_version_to_path called without scm_version"
131131
):
132132
write_version_to_path(
133133
target=target_file,
134134
template=None, # Use default template
135135
version="1.2.3",
136-
scm_version=None, # Explicitly passing None should warn
137136
)
138137

139138
# Verify the file was created and contains the expected content

vcs-versioning/src/vcs_versioning/_dump_version.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,17 @@
1616
log = logging.getLogger(__name__)
1717

1818

19+
class MISSING:
20+
def __repr__(self) -> str:
21+
return "<MISSING>"
22+
23+
def __bool__(self) -> bool:
24+
return False
25+
26+
27+
MISSING_VAL = MISSING()
28+
29+
1930
DEFAULT_TEMPLATES = {
2031
".py": """\
2132
# file generated by vcs-versioning
@@ -89,7 +100,7 @@ def write_version_to_path(
89100
target: Path,
90101
template: str | None,
91102
version: str,
92-
scm_version: ScmVersion | None = None,
103+
scm_version: ScmVersion | MISSING | None = MISSING_VAL,
93104
) -> None:
94105
"""Write version information to a file using a template.
95106
@@ -102,7 +113,7 @@ def write_version_to_path(
102113
final_template = _validate_template(target, template)
103114
log.debug("dump %s into %s", version, target)
104115
version_tuple = _version_as_tuple(version)
105-
if scm_version is None:
116+
if scm_version is MISSING_VAL:
106117
warnings.warn(
107118
"write_version_to_path called without scm_version parameter. "
108119
"This will be required in a future version. "
@@ -125,7 +136,7 @@ def dump_version(
125136
version: str,
126137
write_to: _t.PathT,
127138
template: str | None = None,
128-
scm_version: ScmVersion | None = None,
139+
scm_version: ScmVersion | MISSING | None = MISSING_VAL,
129140
) -> None:
130141
"""Write version information to a file relative to root.
131142

0 commit comments

Comments
 (0)