Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deprecate transitive_python_versions #648

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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