Skip to content

Commit

Permalink
Fix ConfigHandler generic
Browse files Browse the repository at this point in the history
  • Loading branch information
Avasam committed Oct 15, 2024
1 parent 857ded2 commit cec7374
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
17 changes: 10 additions & 7 deletions setuptools/config/setupcfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
List,
Tuple,
TypeVar,
Union,
cast,
)

Expand All @@ -53,7 +52,7 @@
while the second element of the tuple is the option value itself
"""
AllCommandOptions = Dict["str", SingleCommandOptions] # cmd name => its options
Target = TypeVar("Target", bound=Union["Distribution", "DistributionMetadata"])
Target = TypeVar("Target", "Distribution", "DistributionMetadata")


def read_configuration(
Expand Down Expand Up @@ -96,7 +95,7 @@ def _apply(
filepath: StrPath,
other_files: Iterable[StrPath] = (),
ignore_option_errors: bool = False,
) -> tuple[ConfigHandler, ...]:
) -> tuple[ConfigMetadataHandler, ConfigOptionsHandler]:
"""Read configuration from ``filepath`` and applies to the ``dist`` object."""
from setuptools.dist import _Distribution

Expand All @@ -122,7 +121,7 @@ def _apply(
return handlers


def _get_option(target_obj: Target, key: str):
def _get_option(target_obj: Distribution | DistributionMetadata, key: str):
"""
Given a target object and option key, get that option from
the target object, either through a get_{key} method or
Expand All @@ -134,10 +133,14 @@ def _get_option(target_obj: Target, key: str):
return getter()


def configuration_to_dict(handlers: tuple[ConfigHandler, ...]) -> dict:
def configuration_to_dict(
handlers: Iterable[
ConfigHandler[Distribution] | ConfigHandler[DistributionMetadata]
],
) -> dict:
"""Returns configuration data gathered by given handlers as a dict.
:param list[ConfigHandler] handlers: Handlers list,
:param Iterable[ConfigHandler] handlers: Handlers list,
usually from parse_configuration()
:rtype: dict
Expand Down Expand Up @@ -254,7 +257,7 @@ def __init__(
ensure_discovered: expand.EnsurePackagesDiscovered,
):
self.ignore_option_errors = ignore_option_errors
self.target_obj = target_obj
self.target_obj: Target = target_obj
self.sections = dict(self._section_options(options))
self.set_options: list[str] = []
self.ensure_discovered = ensure_discovered
Expand Down
4 changes: 2 additions & 2 deletions setuptools/tests/config/test_setupcfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import pytest
from packaging.requirements import InvalidRequirement

from setuptools.config.setupcfg import ConfigHandler, read_configuration
from setuptools.config.setupcfg import ConfigHandler, Target, read_configuration
from setuptools.dist import Distribution, _Distribution
from setuptools.warnings import SetuptoolsDeprecationWarning

Expand All @@ -16,7 +16,7 @@
from distutils.errors import DistutilsFileError, DistutilsOptionError


class ErrConfigHandler(ConfigHandler):
class ErrConfigHandler(ConfigHandler[Target]):
"""Erroneous handler. Fails to implement required methods."""

section_prefix = "**err**"
Expand Down

0 comments on commit cec7374

Please sign in to comment.