2121
2222from packaging .markers import default_environment as marker_env
2323from packaging .requirements import InvalidRequirement , Requirement
24- from packaging .specifiers import SpecifierSet
2524from packaging .version import InvalidVersion , Version
2625
26+ from .. import _static
2727from .._path import StrPath
2828from ..errors import FileError , OptionError
2929from ..warnings import SetuptoolsDeprecationWarning
@@ -309,7 +309,7 @@ def _parse_list(cls, value, separator=','):
309309
310310 :param value:
311311 :param separator: List items separator character.
312- :rtype: list
312+ :rtype: tuple
313313 """
314314 if isinstance (value , list ): # _get_parser_compound case
315315 return value
@@ -367,7 +367,7 @@ def parser(value):
367367 f'Only strings are accepted for the { key } field, '
368368 'files are not accepted'
369369 )
370- return value
370+ return _static . Str ( value )
371371
372372 return parser
373373
@@ -387,15 +387,15 @@ def _parse_file(self, value, root_dir: StrPath | None):
387387 include_directive = 'file:'
388388
389389 if not isinstance (value , str ):
390- return value
390+ return _static . convert ( value )
391391
392392 if not value .startswith (include_directive ):
393- return value
393+ return _static . Str ( value )
394394
395395 spec = value [len (include_directive ) :]
396396 filepaths = [path .strip () for path in spec .split (',' )]
397397 self ._referenced_files .update (filepaths )
398- return expand .read_files (filepaths , root_dir )
398+ return _static . Str ( expand .read_files (filepaths , root_dir )) # Too optimistic?
399399
400400 def _parse_attr (self , value , package_dir , root_dir : StrPath ):
401401 """Represents value as a module attribute.
@@ -409,7 +409,7 @@ def _parse_attr(self, value, package_dir, root_dir: StrPath):
409409 """
410410 attr_directive = 'attr:'
411411 if not value .startswith (attr_directive ):
412- return value
412+ return _static . Str ( value )
413413
414414 attr_desc = value .replace (attr_directive , '' )
415415
@@ -473,7 +473,7 @@ def parse_section(self, section_options) -> None:
473473 for name , (_ , value ) in section_options .items ():
474474 with contextlib .suppress (KeyError ):
475475 # Keep silent for a new option may appear anytime.
476- self [name ] = value
476+ self [name ] = _static . convert ( value )
477477
478478 def parse (self ) -> None :
479479 """Parses configuration file items from one
@@ -548,23 +548,23 @@ def __init__(
548548 @property
549549 def parsers (self ):
550550 """Metadata item name to parser function mapping."""
551- parse_list = self ._parse_list
551+ parse_tuple_static = self ._get_parser_compound (self ._parse_list , _static .Tuple )
552+ parse_dict_static = self ._get_parser_compound (self ._parse_dict , _static .Mapping )
552553 parse_file = partial (self ._parse_file , root_dir = self .root_dir )
553- parse_dict = self ._parse_dict
554554 exclude_files_parser = self ._exclude_files_parser
555555
556556 return {
557- 'platforms' : parse_list ,
558- 'keywords' : parse_list ,
559- 'provides' : parse_list ,
560- 'obsoletes' : parse_list ,
561- 'classifiers' : self ._get_parser_compound (parse_file , parse_list ),
557+ 'platforms' : parse_tuple_static ,
558+ 'keywords' : parse_tuple_static ,
559+ 'provides' : parse_tuple_static ,
560+ 'obsoletes' : parse_tuple_static ,
561+ 'classifiers' : self ._get_parser_compound (parse_file , parse_tuple_static ),
562562 'license' : exclude_files_parser ('license' ),
563- 'license_files' : parse_list ,
563+ 'license_files' : parse_tuple_static ,
564564 'description' : parse_file ,
565565 'long_description' : parse_file ,
566566 'version' : self ._parse_version ,
567- 'project_urls' : parse_dict ,
567+ 'project_urls' : parse_dict_static ,
568568 }
569569
570570 def _parse_version (self , value ):
@@ -620,20 +620,19 @@ def _parse_requirements_list(self, label: str, value: str):
620620 _warn_accidental_env_marker_misconfig (label , value , parsed )
621621 # Filter it to only include lines that are not comments. `parse_list`
622622 # will have stripped each line and filtered out empties.
623- return [ line for line in parsed if not line .startswith ("#" )]
623+ return _static . Tuple ( line for line in parsed if not line .startswith ("#" ))
624624
625625 @property
626626 def parsers (self ):
627627 """Metadata item name to parser function mapping."""
628628 parse_list = self ._parse_list
629629 parse_bool = self ._parse_bool
630- parse_dict = self ._parse_dict
631630 parse_cmdclass = self ._parse_cmdclass
632631
633632 return {
634633 'zip_safe' : parse_bool ,
635634 'include_package_data' : parse_bool ,
636- 'package_dir' : parse_dict ,
635+ 'package_dir' : self . _parse_dict ,
637636 'scripts' : parse_list ,
638637 'eager_resources' : parse_list ,
639638 'dependency_links' : parse_list ,
@@ -650,7 +649,7 @@ def parsers(self):
650649 'packages' : self ._parse_packages ,
651650 'entry_points' : self ._parse_file_in_root ,
652651 'py_modules' : parse_list ,
653- 'python_requires' : SpecifierSet ,
652+ 'python_requires' : _static . SpeficierSet ,
654653 'cmdclass' : parse_cmdclass ,
655654 }
656655
@@ -737,7 +736,7 @@ def parse_section_extras_require(self, section_options) -> None:
737736 lambda k , v : self ._parse_requirements_list (f"extras_require[{ k } ]" , v ),
738737 )
739738
740- self ['extras_require' ] = parsed
739+ self ['extras_require' ] = _static . Mapping ( parsed )
741740
742741 def parse_section_data_files (self , section_options ) -> None :
743742 """Parses `data_files` configuration file section.
0 commit comments