88"""
99
1010
11- from typing import Any , Callable , Dict , List , Optional , Union
11+ from typing import Callable , Dict , List , Optional , Union
1212
1313from pylint import utils as pylint_utils
1414
1515_ArgumentTypes = Union [str , List [str ]]
1616"""List of possible argument types."""
1717
1818
19- def _csv_validator (value : Union [ str , List [ str ]] ) -> List [str ]:
20- """Validates a comma separated string."""
19+ def _csv_transformer (value : str ) -> List [str ]:
20+ """Transforms a comma separated string."""
2121 return pylint_utils ._check_csv (value )
2222
2323
24- _ASSIGNMENT_VALIDATORS : Dict [str , Callable [[Any ], _ArgumentTypes ]] = {
24+ _TYPE_TRANSFORMERS : Dict [str , Callable [[str ], _ArgumentTypes ]] = {
2525 "choice" : str ,
26- "csv" : _csv_validator ,
26+ "csv" : _csv_transformer ,
2727}
28- """Validators for all assignment types."""
28+ """Type transformers for all argument types.
29+
30+ A transformer should accept a string and return one of the supported
31+ Argument types. It will only be called when parsing 1) command-line,
32+ 2) configuration files and 3) a string default value.
33+ Non-string default values are assumed to be of the correct type.
34+ """
2935
3036
3137class _Argument :
@@ -52,10 +58,10 @@ def __init__(
5258 self .action = action
5359 """The action to perform with the argument."""
5460
55- self .type = _ASSIGNMENT_VALIDATORS [arg_type ]
56- """A validator function that returns and checks the type of the argument."""
61+ self .type = _TYPE_TRANSFORMERS [arg_type ]
62+ """A transformer function that returns a transformed type of the argument."""
5763
58- self .default = self . type ( default )
64+ self .default = default
5965 """The default value of the argument."""
6066
6167 self .choices = choices
0 commit comments