Skip to content

Commit 1429bf5

Browse files
Avasamabravalheri
authored andcommitted
Fix ConfigHandler generic
1 parent 3403ffd commit 1429bf5

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

setuptools/config/setupcfg.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
List,
2828
Tuple,
2929
TypeVar,
30-
Union,
3130
cast,
3231
)
3332

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

5857

5958
def read_configuration(
@@ -96,7 +95,7 @@ def _apply(
9695
filepath: StrPath,
9796
other_files: Iterable[StrPath] = (),
9897
ignore_option_errors: bool = False,
99-
) -> tuple[ConfigHandler, ...]:
98+
) -> tuple[ConfigMetadataHandler, ConfigOptionsHandler]:
10099
"""Read configuration from ``filepath`` and applies to the ``dist`` object."""
101100
from setuptools.dist import _Distribution
102101

@@ -122,7 +121,7 @@ def _apply(
122121
return handlers
123122

124123

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

136135

137-
def configuration_to_dict(handlers: tuple[ConfigHandler, ...]) -> dict:
136+
def configuration_to_dict(
137+
handlers: Iterable[
138+
ConfigHandler[Distribution] | ConfigHandler[DistributionMetadata]
139+
],
140+
) -> dict:
138141
"""Returns configuration data gathered by given handlers as a dict.
139142
140-
:param list[ConfigHandler] handlers: Handlers list,
143+
:param Iterable[ConfigHandler] handlers: Handlers list,
141144
usually from parse_configuration()
142145
143146
:rtype: dict
@@ -254,7 +257,7 @@ def __init__(
254257
ensure_discovered: expand.EnsurePackagesDiscovered,
255258
):
256259
self.ignore_option_errors = ignore_option_errors
257-
self.target_obj = target_obj
260+
self.target_obj: Target = target_obj
258261
self.sections = dict(self._section_options(options))
259262
self.set_options: list[str] = []
260263
self.ensure_discovered = ensure_discovered

setuptools/tests/config/test_setupcfg.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import pytest
88
from packaging.requirements import InvalidRequirement
99

10-
from setuptools.config.setupcfg import ConfigHandler, read_configuration
10+
from setuptools.config.setupcfg import ConfigHandler, Target, read_configuration
1111
from setuptools.dist import Distribution, _Distribution
1212
from setuptools.warnings import SetuptoolsDeprecationWarning
1313

@@ -16,7 +16,7 @@
1616
from distutils.errors import DistutilsFileError, DistutilsOptionError
1717

1818

19-
class ErrConfigHandler(ConfigHandler):
19+
class ErrConfigHandler(ConfigHandler[Target]):
2020
"""Erroneous handler. Fails to implement required methods."""
2121

2222
section_prefix = "**err**"

0 commit comments

Comments
 (0)