@@ -552,31 +552,31 @@ def __str__(self):
552
552
553
553
554
554
class Argument :
555
- """class that mimics the necessary behaviour of optparse.Option """
555
+ """class that mimics the necessary behaviour of optparse.Option
556
+
557
+ its currently a least effort implementation
558
+ and ignoring choices and integer prefixes
559
+ https://docs.python.org/3/library/optparse.html#optparse-standard-option-types
560
+ """
556
561
_typ_map = {
557
562
'int' : int ,
558
563
'string' : str ,
559
- }
560
- # enable after some grace period for plugin writers
561
- TYPE_WARN = False
564
+ 'float' : float ,
565
+ 'complex' : complex ,
566
+ }
562
567
563
568
def __init__ (self , * names , ** attrs ):
564
569
"""store parms in private vars for use in add_argument"""
565
570
self ._attrs = attrs
566
571
self ._short_opts = []
567
572
self ._long_opts = []
568
573
self .dest = attrs .get ('dest' )
569
- if self .TYPE_WARN :
570
- try :
571
- help = attrs ['help' ]
572
- if '%default' in help :
573
- warnings .warn (
574
- 'pytest now uses argparse. "%default" should be'
575
- ' changed to "%(default)s" ' ,
576
- FutureWarning ,
577
- stacklevel = 3 )
578
- except KeyError :
579
- 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 )
580
580
try :
581
581
typ = attrs ['type' ]
582
582
except KeyError :
@@ -585,25 +585,23 @@ def __init__(self, *names, **attrs):
585
585
# this might raise a keyerror as well, don't want to catch that
586
586
if isinstance (typ , py .builtin ._basestring ):
587
587
if typ == 'choice' :
588
- if self .TYPE_WARN :
589
- warnings .warn (
590
- 'type argument to addoption() is a string %r.'
591
- ' For parsearg this is optional and when supplied '
592
- ' should be a type.'
593
- ' (options: %s)' % (typ , names ),
594
- FutureWarning ,
595
- 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 )
596
595
# argparse expects a type here take it from
597
596
# the type of the first element
598
597
attrs ['type' ] = type (attrs ['choices' ][0 ])
599
598
else :
600
- if self .TYPE_WARN :
601
- warnings .warn (
602
- 'type argument to addoption() is a string %r.'
603
- ' For parsearg this should be a type.'
604
- ' (options: %s)' % (typ , names ),
605
- FutureWarning ,
606
- 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 )
607
605
attrs ['type' ] = Argument ._typ_map [typ ]
608
606
# used in test_parseopt -> test_parse_defaultgetter
609
607
self .type = attrs ['type' ]
0 commit comments