Skip to content

Commit 61cc5c4

Browse files
argument parsing: always warn for string types
fix #1741
1 parent 317b3f2 commit 61cc5c4

File tree

1 file changed

+19
-28
lines changed

1 file changed

+19
-28
lines changed

_pytest/config.py

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -564,26 +564,19 @@ class Argument:
564564
'float': float,
565565
'complex': complex,
566566
}
567-
# enable after some grace period for plugin writers
568-
TYPE_WARN = False
569567

570568
def __init__(self, *names, **attrs):
571569
"""store parms in private vars for use in add_argument"""
572570
self._attrs = attrs
573571
self._short_opts = []
574572
self._long_opts = []
575573
self.dest = attrs.get('dest')
576-
if self.TYPE_WARN:
577-
try:
578-
help = attrs['help']
579-
if '%default' in help:
580-
warnings.warn(
581-
'pytest now uses argparse. "%default" should be'
582-
' changed to "%(default)s" ',
583-
FutureWarning,
584-
stacklevel=3)
585-
except KeyError:
586-
pass
574+
if '%default' in (attrs.get('help') or ''):
575+
warnings.warn(
576+
'pytest now uses argparse. "%default" should be'
577+
' changed to "%(default)s" ',
578+
DeprecationWarning,
579+
stacklevel=3)
587580
try:
588581
typ = attrs['type']
589582
except KeyError:
@@ -592,25 +585,23 @@ def __init__(self, *names, **attrs):
592585
# this might raise a keyerror as well, don't want to catch that
593586
if isinstance(typ, py.builtin._basestring):
594587
if typ == 'choice':
595-
if self.TYPE_WARN:
596-
warnings.warn(
597-
'type argument to addoption() is a string %r.'
598-
' For parsearg this is optional and when supplied '
599-
' should be a type.'
600-
' (options: %s)' % (typ, names),
601-
FutureWarning,
602-
stacklevel=3)
588+
warnings.warn(
589+
'type argument to addoption() is a string %r.'
590+
' For parsearg this is optional and when supplied '
591+
' should be a type.'
592+
' (options: %s)' % (typ, names),
593+
DeprecationWarning,
594+
stacklevel=3)
603595
# argparse expects a type here take it from
604596
# the type of the first element
605597
attrs['type'] = type(attrs['choices'][0])
606598
else:
607-
if self.TYPE_WARN:
608-
warnings.warn(
609-
'type argument to addoption() is a string %r.'
610-
' For parsearg this should be a type.'
611-
' (options: %s)' % (typ, names),
612-
FutureWarning,
613-
stacklevel=3)
599+
warnings.warn(
600+
'type argument to addoption() is a string %r.'
601+
' For parsearg this should be a type.'
602+
' (options: %s)' % (typ, names),
603+
DeprecationWarning,
604+
stacklevel=3)
614605
attrs['type'] = Argument._typ_map[typ]
615606
# used in test_parseopt -> test_parse_defaultgetter
616607
self.type = attrs['type']

0 commit comments

Comments
 (0)