prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  21.3 regression with legacy resolver
  Assuming the following project with an empty `pyproject.toml` and the following `setup.cfg`:
  
  ```ini
  [metadata]
  name = pkgb
  version = 1.0
  
  [options]
  install_requires =
      wrapt
  ```
  
  We get the following stack trace, using pip main branch, today:
  
  ```console
  $ pip install --use-deprecated=legacy-resolver -e ./pkgb
  Obtaining file:///home/me/tmp/brol/pkgb
    Installing build dependencies ... done
    Getting requirements to build wheel ... done
      Preparing wheel metadata ... done
  Requirement already satisfied: wrapt in /home/me/.virtualenvs/tempenv-49ea1126817e6/lib/python3.8/site-packages (from pkgb==1.0) (1.12.1)
  ERROR: Exception:
  Traceback (most recent call last):
    File "/home/me/pip/src/pip/_internal/cli/base_command.py", line 179, in exc_logging_wrapper
      status = run_func(*args)
    File "/home/me/pip/src/pip/_internal/cli/req_command.py", line 203, in wrapper
      return func(self, options, args)
    File "/home/me/pip/src/pip/_internal/commands/install.py", line 334, in run
      requirement_set = resolver.resolve(
    File "/home/me/pip/src/pip/_internal/resolution/legacy/resolver.py", line 181, in resolve
      discovered_reqs.extend(self._resolve_one(requirement_set, req))
    File "/home/me/pip/src/pip/_internal/resolution/legacy/resolver.py", line 382, in _resolve_one
      _check_dist_requires_python(
    File "/home/me/pip/src/pip/_internal/resolution/legacy/resolver.py", line 75, in _check_dist_requires_python
      requires_python = str(dist.requires_python)
    File "/home/me/pip/src/pip/_vendor/pkg_resources/__init__.py", line 2816, in __getattr__
      return getattr(self._provider, attr)
  AttributeError: 'PathMetadata' object has no attribute 'requires_python'
  ```
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `src/pip/_internal/distributions/installed.py`
  Content:
  ```
  1 from pip._internal.distributions.base import AbstractDistribution
  2 from pip._internal.index.package_finder import PackageFinder
  3 from pip._internal.metadata import BaseDistribution
  4 
  5 
  6 class InstalledDistribution(AbstractDistribution):
  7     """Represents an installed package.
  8 
  9     This does not need any preparation as the required information has already
  10     been computed.
  11     """
  12 
  13     def get_metadata_distribution(self) -> BaseDistribution:
  14         assert self.req.satisfied_by is not None, "not actually installed"
  15         return self.req.satisfied_by
  16 
  17     def prepare_distribution_metadata(
  18         self, finder: PackageFinder, build_isolation: bool
  19     ) -> None:
  20         pass
  21
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/src/pip/_internal/distributions/installed.py b/src/pip/_internal/distributions/installed.py
  --- a/src/pip/_internal/distributions/installed.py
  +++ b/src/pip/_internal/distributions/installed.py
  @@ -11,8 +11,10 @@
       """
   
       def get_metadata_distribution(self) -> BaseDistribution:
  +        from pip._internal.metadata.pkg_resources import Distribution as _Dist
  +
           assert self.req.satisfied_by is not None, "not actually installed"
  -        return self.req.satisfied_by
  +        return _Dist(self.req.satisfied_by)
   
       def prepare_distribution_metadata(
           self, finder: PackageFinder, build_isolation: bool
  
verification_info: {"golden_diff": "diff --git a/src/pip/_internal/distributions/installed.py b/src/pip/_internal/distributions/installed.py\n--- a/src/pip/_internal/distributions/installed.py\n+++ b/src/pip/_internal/distributions/installed.py\n@@ -11,8 +11,10 @@\n     \"\"\"\n \n     def get_metadata_distribution(self) -> BaseDistribution:\n+        from pip._internal.metadata.pkg_resources import Distribution as _Dist\n+\n         assert self.req.satisfied_by is not None, \"not actually installed\"\n-        return self.req.satisfied_by\n+        return _Dist(self.req.satisfied_by)\n \n     def prepare_distribution_metadata(\n         self, finder: PackageFinder, build_isolation: bool\n", "issue": "21.3 regression with legacy resolver\nAssuming the following project with an empty `pyproject.toml` and the following `setup.cfg`:\r\n\r\n```ini\r\n[metadata]\r\nname = pkgb\r\nversion = 1.0\r\n\r\n[options]\r\ninstall_requires =\r\n    wrapt\r\n```\r\n\r\nWe get the following stack trace, using pip main branch, today:\r\n\r\n```console\r\n$ pip install --use-deprecated=legacy-resolver -e ./pkgb\r\nObtaining file:///home/me/tmp/brol/pkgb\r\n  Installing build dependencies ... done\r\n  Getting requirements to build wheel ... done\r\n    Preparing wheel metadata ... done\r\nRequirement already satisfied: wrapt in /home/me/.virtualenvs/tempenv-49ea1126817e6/lib/python3.8/site-packages (from pkgb==1.0) (1.12.1)\r\nERROR: Exception:\r\nTraceback (most recent call last):\r\n  File \"/home/me/pip/src/pip/_internal/cli/base_command.py\", line 179, in exc_logging_wrapper\r\n    status = run_func(*args)\r\n  File \"/home/me/pip/src/pip/_internal/cli/req_command.py\", line 203, in wrapper\r\n    return func(self, options, args)\r\n  File \"/home/me/pip/src/pip/_internal/commands/install.py\", line 334, in run\r\n    requirement_set = resolver.resolve(\r\n  File \"/home/me/pip/src/pip/_internal/resolution/legacy/resolver.py\", line 181, in resolve\r\n    discovered_reqs.extend(self._resolve_one(requirement_set, req))\r\n  File \"/home/me/pip/src/pip/_internal/resolution/legacy/resolver.py\", line 382, in _resolve_one\r\n    _check_dist_requires_python(\r\n  File \"/home/me/pip/src/pip/_internal/resolution/legacy/resolver.py\", line 75, in _check_dist_requires_python\r\n    requires_python = str(dist.requires_python)\r\n  File \"/home/me/pip/src/pip/_vendor/pkg_resources/__init__.py\", line 2816, in __getattr__\r\n    return getattr(self._provider, attr)\r\nAttributeError: 'PathMetadata' object has no attribute 'requires_python'\r\n```\r\n\n", "before_files": [{"content": "from pip._internal.distributions.base import AbstractDistribution\nfrom pip._internal.index.package_finder import PackageFinder\nfrom pip._internal.metadata import BaseDistribution\n\n\nclass InstalledDistribution(AbstractDistribution):\n    \"\"\"Represents an installed package.\n\n    This does not need any preparation as the required information has already\n    been computed.\n    \"\"\"\n\n    def get_metadata_distribution(self) -> BaseDistribution:\n        assert self.req.satisfied_by is not None, \"not actually installed\"\n        return self.req.satisfied_by\n\n    def prepare_distribution_metadata(\n        self, finder: PackageFinder, build_isolation: bool\n    ) -> None:\n        pass\n", "path": "src/pip/_internal/distributions/installed.py"}], "after_files": [{"content": "from pip._internal.distributions.base import AbstractDistribution\nfrom pip._internal.index.package_finder import PackageFinder\nfrom pip._internal.metadata import BaseDistribution\n\n\nclass InstalledDistribution(AbstractDistribution):\n    \"\"\"Represents an installed package.\n\n    This does not need any preparation as the required information has already\n    been computed.\n    \"\"\"\n\n    def get_metadata_distribution(self) -> BaseDistribution:\n        from pip._internal.metadata.pkg_resources import Distribution as _Dist\n\n        assert self.req.satisfied_by is not None, \"not actually installed\"\n        return _Dist(self.req.satisfied_by)\n\n    def prepare_distribution_metadata(\n        self, finder: PackageFinder, build_isolation: bool\n    ) -> None:\n        pass\n", "path": "src/pip/_internal/distributions/installed.py"}]}