Skip to content

[BUG] pkg_resources.Requirement.parse changed exception class on 70.0.0 #4414

Open
@pradyunsg

Description

@pradyunsg

setuptools version

70.0.0

Python version

N/A

OS

N/A

Additional environment information

N/A

Description

In setuptools 70, Requirement.parse raises a different (private) exception class coming out of the _vendor path rather than the extern path. This means that there is no way for a caller of that method to catch the raised exception without reaching into the _vendor directory.

This was changed by e999582, if I understand correctly.

Expected behavior

The exception class is not changed, or the class of the exception raised is publicly accessible.

How to Reproduce

  1. Create a file with the following contents:
import warnings

warnings.simplefilter("ignore", Warning)

import setuptools
import pkg_resources  # noqa
from pkg_resources.extern.packaging.requirements import (  # noqa
    InvalidRequirement as ErrorFromExtern,
)
from pkg_resources._vendor.packaging.requirements import (  # noqa
    InvalidRequirement as ErrorFromVendor,
)

try:
    pkg_resources.Requirement.parse("a b")
except Exception as e:
    print(setuptools.__version__)
    print("  ", e.__class__)
    print("  ", isinstance(e, ErrorFromExtern))
    print("  ", isinstance(e, ErrorFromVendor))
  1. Run this file in an environment with setuptools 70.0.0 and then in an environment with setuptools==69.5.1.
  2. See the different class of the exception.

Output

69.5.1
   <class 'pkg_resources.extern.packaging.requirements.InvalidRequirement'>
   True
   False
70.0.0
   <class 'pkg_resources._vendor.packaging.requirements.InvalidRequirement'>
   False
   True

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs TriageIssues that need to be evaluated for severity and status.bughelp wanted

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions