-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Closed
Labels
topic: configrelated to config handling, argument parsing and config filerelated to config handling, argument parsing and config filetopic: typingtype-annotation issuetype-annotation issuetype: enhancementnew feature or API change, should be merged into features branchnew feature or API change, should be merged into features branchtype: feature-branchnew feature or API change, should be merged into features branchnew feature or API change, should be merged into features branchtype: proposalproposal for a new feature, often to gather opinions or design the API around the new featureproposal for a new feature, often to gather opinions or design the API around the new feature
Description
What's the problem this feature will solve?
Avoid writing extra code to convert data type from string to a numeric type (integer, float, etc)
Describe the solution you'd like
Parser.addini
method receives a parameter called type
that can be any of these string literals:
type: Optional[
"Literal['string', 'paths', 'pathlist', 'args', 'linelist', 'bool']"
] = None,
Add the literals (int
, float
) and have pytest
to do the type check and conversion behind the scene.
Alternative Solutions
parser.addini(
"my_param",
type="string",
default="1.0",
help="My float param."
)
def my_param(request):
try:
return float(request.config.getini("my_param"))
except:
return 1.0 #The default value set with default="1.0",
With the implementation of this feature, this can be reduced to this;
parser.addini(
"my_param",
type="float",
default="1.0",
help="My float param."
)
def my_param(request):
return request.config.getini("my_param")
Additional context
Metadata
Metadata
Assignees
Labels
topic: configrelated to config handling, argument parsing and config filerelated to config handling, argument parsing and config filetopic: typingtype-annotation issuetype-annotation issuetype: enhancementnew feature or API change, should be merged into features branchnew feature or API change, should be merged into features branchtype: feature-branchnew feature or API change, should be merged into features branchnew feature or API change, should be merged into features branchtype: proposalproposal for a new feature, often to gather opinions or design the API around the new featureproposal for a new feature, often to gather opinions or design the API around the new feature