From 83c399a3498b7855746ec640710fa2002afb31bd Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 5 Mar 2023 22:19:48 -0500 Subject: [PATCH] Simplify _section_options using str.partition and a generator. --- setuptools/config/setupcfg.py | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/setuptools/config/setupcfg.py b/setuptools/config/setupcfg.py index 1b61701376..03a446fd2a 100644 --- a/setuptools/config/setupcfg.py +++ b/setuptools/config/setupcfg.py @@ -253,7 +253,7 @@ def __init__( ): self.ignore_option_errors = ignore_option_errors self.target_obj = target_obj - self.sections = self._section_options(options) + self.sections = dict(self._section_options(options)) self.set_options: List[str] = [] self.ensure_discovered = ensure_discovered self._referenced_files: Set[str] = set() @@ -263,17 +263,11 @@ def __init__( @classmethod def _section_options(cls, options: AllCommandOptions): - sections: AllCommandOptions = {} - - section_prefix = cls.section_prefix - for section_name, section_options in options.items(): - if not section_name.startswith(section_prefix): + for full_name, value in options.items(): + pre, sep, name = full_name.partition(cls.section_prefix) + if pre: continue - - section_name = section_name.replace(section_prefix, '').strip('.') - sections[section_name] = section_options - - return sections + yield name.lstrip('.'), value @property def parsers(self):