Skip to content

Commit

Permalink
Merge pull request #1 from pypa/master
Browse files Browse the repository at this point in the history
Don't have packaging.tags.compatible_tags() reuse an iterable (pypa#258)
  • Loading branch information
sthagen authored Jan 22, 2020
2 parents e664cdd + d49fdc5 commit 9e31427
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 2 additions & 3 deletions packaging/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ def _py_interpreter_range(py_version):
def compatible_tags(
python_version=None, # type: Optional[PythonVersion]
interpreter=None, # type: Optional[str]
platforms=None, # type: Optional[Iterator[str]]
platforms=None, # type: Optional[Iterable[str]]
):
# type: (...) -> Iterator[Tag]
"""
Expand All @@ -328,8 +328,7 @@ def compatible_tags(
"""
if not python_version:
python_version = sys.version_info[:2]
if not platforms:
platforms = _platform_tags()
platforms = list(platforms or _platform_tags())
for version in _py_interpreter_range(python_version):
for platform_ in platforms:
yield Tag(version, "none", platform_)
Expand Down
5 changes: 4 additions & 1 deletion tests/test_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -923,12 +923,15 @@ def test_default_interpreter(self):
]

def test_default_platforms(self, monkeypatch):
monkeypatch.setattr(tags, "_platform_tags", lambda: ["plat"])
monkeypatch.setattr(tags, "_platform_tags", lambda: iter(["plat", "plat2"]))
result = list(tags.compatible_tags((3, 1), "cp31"))
assert result == [
tags.Tag("py31", "none", "plat"),
tags.Tag("py31", "none", "plat2"),
tags.Tag("py3", "none", "plat"),
tags.Tag("py3", "none", "plat2"),
tags.Tag("py30", "none", "plat"),
tags.Tag("py30", "none", "plat2"),
tags.Tag("cp31", "none", "any"),
tags.Tag("py31", "none", "any"),
tags.Tag("py3", "none", "any"),
Expand Down

0 comments on commit 9e31427

Please sign in to comment.