AdithyaSK's picture
AdithyaSK HF Staff
Publish 100 swe_next Harbor tasks
d40299b verified
|
Raw History Blame
2.72 kB

packaging.tags is missing a pure_python_tags() function

Description

The packaging.tags module does not expose a pure_python_tags() function, but one is needed to generate pure-Python compatibility tags (py*-none-any) without having to query the running platform. Currently, the only way to get those tags is through compatible_tags(), which bundles them with platform-specific and ABI-specific tags.

When trying to call tags.pure_python_tags(...), you get:

AttributeError: module 'packaging.tags' has no attribute 'pure_python_tags'. Did you mean: 'cpython_tags'?

Here is a minimal reproduction:

from packaging import tags

# Should yield: py33-none-any, py3-none-any, py32-none-any, py31-none-any, py30-none-any
result = list(tags.pure_python_tags((3, 3)))

# Should yield a single tag: py3-none-any
single = list(tags.pure_python_tags((3,)))

# Should raise ValueError
try:
    list(tags.pure_python_tags(()))
except ValueError as e:
    print(e)  # expected: "must contain at least one item"

# Should default to sys.version_info[:2] when called with no arguments
default = list(tags.pure_python_tags())

Additionally, pure_python_tags() should not call platform_tags() internally — the whole point is that it works without inspecting the running platform:

from packaging import tags

# Patching platform_tags to detect if it gets called
original = tags.platform_tags
tags.platform_tags = lambda: (_ for _ in ()).throw(AssertionError("platform queried!"))

# This should work fine without triggering platform detection
result = list(tags.pure_python_tags((3,)))
print(result)  # [<Tag py3-none-any>]

tags.platform_tags = original

Expected behavior

  • tags.pure_python_tags((3, 3)) returns an iterator of Tag objects: py33-none-any, py3-none-any, py32-none-any, py31-none-any, py30-none-any.
  • tags.pure_python_tags((3,)) returns [Tag("py3", "none", "any")].
  • tags.pure_python_tags(()) raises ValueError with a message like "must contain at least one item".
  • tags.pure_python_tags() (no args) defaults to sys.version_info[:2].
  • The function never queries the running platform.

Actual behavior

Calling tags.pure_python_tags(...) raises:

AttributeError: module 'packaging.tags' has no attribute 'pure_python_tags'. Did you mean: 'cpython_tags'?

The function simply does not exist in the module.

Work in /workspace. Submit your fix in the existing Python source files under src/packaging. Preserve the other public behavior. The environment is offline; dependencies are preinstalled. Grading runs the repository's test suite in a fresh environment, using your submitted source files.