parent
317b3f257d
commit
61cc5c4d4e
|
@ -564,8 +564,6 @@ class Argument:
|
||||||
'float': float,
|
'float': float,
|
||||||
'complex': complex,
|
'complex': complex,
|
||||||
}
|
}
|
||||||
# enable after some grace period for plugin writers
|
|
||||||
TYPE_WARN = False
|
|
||||||
|
|
||||||
def __init__(self, *names, **attrs):
|
def __init__(self, *names, **attrs):
|
||||||
"""store parms in private vars for use in add_argument"""
|
"""store parms in private vars for use in add_argument"""
|
||||||
|
@ -573,17 +571,12 @@ class Argument:
|
||||||
self._short_opts = []
|
self._short_opts = []
|
||||||
self._long_opts = []
|
self._long_opts = []
|
||||||
self.dest = attrs.get('dest')
|
self.dest = attrs.get('dest')
|
||||||
if self.TYPE_WARN:
|
if '%default' in (attrs.get('help') or ''):
|
||||||
try:
|
warnings.warn(
|
||||||
help = attrs['help']
|
'pytest now uses argparse. "%default" should be'
|
||||||
if '%default' in help:
|
' changed to "%(default)s" ',
|
||||||
warnings.warn(
|
DeprecationWarning,
|
||||||
'pytest now uses argparse. "%default" should be'
|
stacklevel=3)
|
||||||
' changed to "%(default)s" ',
|
|
||||||
FutureWarning,
|
|
||||||
stacklevel=3)
|
|
||||||
except KeyError:
|
|
||||||
pass
|
|
||||||
try:
|
try:
|
||||||
typ = attrs['type']
|
typ = attrs['type']
|
||||||
except KeyError:
|
except KeyError:
|
||||||
|
@ -592,25 +585,23 @@ class Argument:
|
||||||
# this might raise a keyerror as well, don't want to catch that
|
# this might raise a keyerror as well, don't want to catch that
|
||||||
if isinstance(typ, py.builtin._basestring):
|
if isinstance(typ, py.builtin._basestring):
|
||||||
if typ == 'choice':
|
if typ == 'choice':
|
||||||
if self.TYPE_WARN:
|
warnings.warn(
|
||||||
warnings.warn(
|
'type argument to addoption() is a string %r.'
|
||||||
'type argument to addoption() is a string %r.'
|
' For parsearg this is optional and when supplied '
|
||||||
' For parsearg this is optional and when supplied '
|
' should be a type.'
|
||||||
' should be a type.'
|
' (options: %s)' % (typ, names),
|
||||||
' (options: %s)' % (typ, names),
|
DeprecationWarning,
|
||||||
FutureWarning,
|
stacklevel=3)
|
||||||
stacklevel=3)
|
|
||||||
# argparse expects a type here take it from
|
# argparse expects a type here take it from
|
||||||
# the type of the first element
|
# the type of the first element
|
||||||
attrs['type'] = type(attrs['choices'][0])
|
attrs['type'] = type(attrs['choices'][0])
|
||||||
else:
|
else:
|
||||||
if self.TYPE_WARN:
|
warnings.warn(
|
||||||
warnings.warn(
|
'type argument to addoption() is a string %r.'
|
||||||
'type argument to addoption() is a string %r.'
|
' For parsearg this should be a type.'
|
||||||
' For parsearg this should be a type.'
|
' (options: %s)' % (typ, names),
|
||||||
' (options: %s)' % (typ, names),
|
DeprecationWarning,
|
||||||
FutureWarning,
|
stacklevel=3)
|
||||||
stacklevel=3)
|
|
||||||
attrs['type'] = Argument._typ_map[typ]
|
attrs['type'] = Argument._typ_map[typ]
|
||||||
# used in test_parseopt -> test_parse_defaultgetter
|
# used in test_parseopt -> test_parse_defaultgetter
|
||||||
self.type = attrs['type']
|
self.type = attrs['type']
|
||||||
|
|
Loading…
Reference in New Issue