Skip to content

Commit

Permalink
deprecate transitive_python_versions (#648)
Browse files Browse the repository at this point in the history
Co-authored-by: Randy Döring <30527984+radoering@users.noreply.github.com>
  • Loading branch information
dimbleby and radoering authored Oct 15, 2023
1 parent 010688e commit 086f933
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
10 changes: 10 additions & 0 deletions src/poetry/core/packages/dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,23 @@ def python_versions(self, value: str) -> None:

@property
def transitive_python_versions(self) -> str:
warnings.warn(
"'transitive_python_versions' is deprecated and will be removed.",
DeprecationWarning,
stacklevel=2,
)
if self._transitive_python_versions is None:
return self._python_versions

return self._transitive_python_versions

@transitive_python_versions.setter
def transitive_python_versions(self, value: str) -> None:
warnings.warn(
"'transitive_python_versions' is deprecated and will be removed.",
DeprecationWarning,
stacklevel=2,
)
self._transitive_python_versions = value
self._transitive_python_constraint = parse_constraint(value)

Expand Down
18 changes: 15 additions & 3 deletions tests/packages/test_dependency.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
from __future__ import annotations

from contextlib import AbstractContextManager
from contextlib import nullcontext
from typing import Any

import pytest

from packaging.utils import canonicalize_name
Expand Down Expand Up @@ -303,7 +307,8 @@ def test_with_constraint() -> None:
'python_version >= "3.7" and python_version < "4.0"'
)
dependency.python_versions = "^3.6"
dependency.transitive_python_versions = "^3.7"
with pytest.warns(DeprecationWarning):
dependency.transitive_python_versions = "^3.7"

new = dependency.with_constraint("^1.2.6")

Expand Down Expand Up @@ -403,7 +408,14 @@ def test_mutable_attributes_not_in_hash(attr_name: str, value: str) -> None:
dependency = Dependency("foo", "^1.2.3")
ref_hash = hash(dependency)

ref_value = getattr(dependency, attr_name)
setattr(dependency, attr_name, value)
if attr_name == "transitive_python_versions":
context: AbstractContextManager[Any] = pytest.warns(DeprecationWarning)
else:
context = nullcontext()

with context:
ref_value = getattr(dependency, attr_name)
with context:
setattr(dependency, attr_name, value)
assert value != ref_value
assert hash(dependency) == ref_hash

0 comments on commit 086f933

Please sign in to comment.