Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 16f2fd0

Browse files
committed
Merged revisions 78600-78601 via svnmerge from
svn+ssh://[email protected]/python/trunk ........ r78600 | benjamin.peterson | 2010-03-02 16:58:01 -0600 (Tue, 02 Mar 2010) | 1 line remove code to avoid BaseException.message bug ........ r78601 | benjamin.peterson | 2010-03-02 17:02:02 -0600 (Tue, 02 Mar 2010) | 1 line remove cross-version compatibility code ........
1 parent 7124a41 commit 16f2fd0

2 files changed

Lines changed: 9 additions & 65 deletions

File tree

Lib/argparse.py

Lines changed: 7 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -95,40 +95,10 @@
9595

9696
from gettext import gettext as _
9797

98-
try:
99-
_set = set
100-
except NameError:
101-
from sets import Set as _set
102-
103-
try:
104-
_basestring = basestring
105-
except NameError:
106-
_basestring = str
107-
108-
try:
109-
_sorted = sorted
110-
except NameError:
111-
112-
def _sorted(iterable, reverse=False):
113-
result = list(iterable)
114-
result.sort()
115-
if reverse:
116-
result.reverse()
117-
return result
118-
11998

12099
def _callable(obj):
121100
return hasattr(obj, '__call__') or hasattr(obj, '__bases__')
122101

123-
# silence Python 2.6 buggy warnings about Exception.message
124-
if _sys.version_info[:2] == (2, 6):
125-
import warnings
126-
warnings.filterwarnings(
127-
action='ignore',
128-
message='BaseException.message has been deprecated as of Python 2.6',
129-
category=DeprecationWarning,
130-
module='argparse')
131-
132102

133103
SUPPRESS = '==SUPPRESS=='
134104

@@ -161,7 +131,7 @@ def __repr__(self):
161131
return '%s(%s)' % (type_name, ', '.join(arg_strings))
162132

163133
def _get_kwargs(self):
164-
return _sorted(self.__dict__.items())
134+
return sorted(self.__dict__.items())
165135

166136
def _get_args(self):
167137
return []
@@ -414,7 +384,7 @@ def get_lines(parts, indent, prefix=None):
414384

415385
def _format_actions_usage(self, actions, groups):
416386
# find group indices and identify actions in groups
417-
group_actions = _set()
387+
group_actions = set()
418388
inserts = {}
419389
for group in groups:
420390
try:
@@ -484,7 +454,7 @@ def _format_actions_usage(self, actions, groups):
484454
parts.append(part)
485455

486456
# insert things at the necessary indices
487-
for i in _sorted(inserts, reverse=True):
457+
for i in sorted(inserts, reverse=True):
488458
parts[i:i] = [inserts[i]]
489459

490460
# join all the action items with spaces
@@ -1714,7 +1684,7 @@ def parse_known_args(self, args=None, namespace=None):
17141684
if not hasattr(namespace, action.dest):
17151685
if action.default is not SUPPRESS:
17161686
default = action.default
1717-
if isinstance(action.default, _basestring):
1687+
if isinstance(action.default, str):
17181688
default = self._get_value(action, default)
17191689
setattr(namespace, action.dest, default)
17201690

@@ -1774,8 +1744,8 @@ def _parse_known_args(self, arg_strings, namespace):
17741744
arg_strings_pattern = ''.join(arg_string_pattern_parts)
17751745

17761746
# converts arg strings to the appropriate and then takes the action
1777-
seen_actions = _set()
1778-
seen_non_default_actions = _set()
1747+
seen_actions = set()
1748+
seen_non_default_actions = set()
17791749

17801750
def take_action(action, argument_strings, option_string=None):
17811751
seen_actions.add(action)
@@ -2188,7 +2158,7 @@ def _get_values(self, action, arg_strings):
21882158
value = action.const
21892159
else:
21902160
value = action.default
2191-
if isinstance(value, _basestring):
2161+
if isinstance(value, str):
21922162
value = self._get_value(action, value)
21932163
self._check_value(action, value)
21942164

Lib/test/test_argparse.py

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -22,29 +22,9 @@
2222
import warnings
2323
import argparse
2424

25-
from test import support
26-
27-
try:
28-
from StringIO import StringIO
29-
except ImportError:
30-
from io import StringIO
31-
32-
try:
33-
set
34-
except NameError:
35-
from sets import Set as set
36-
37-
try:
38-
sorted
39-
except NameError:
40-
41-
def sorted(iterable, reverse=False):
42-
result = list(iterable)
43-
result.sort()
44-
if reverse:
45-
result.reverse()
46-
return result
25+
from io import StringIO
4726

27+
from test import support
4828

4929
class TestCase(unittest.TestCase):
5030

@@ -4183,12 +4163,6 @@ def test(self):
41834163

41844164
def test_main():
41854165
with warnings.catch_warnings():
4186-
# silence Python 2.6 buggy warnings about Exception.message
4187-
warnings.filterwarnings(
4188-
action='ignore',
4189-
message='BaseException.message has been deprecated as of'
4190-
'Python 2.6',
4191-
category=DeprecationWarning)
41924166
# silence warnings about version argument - these are expected
41934167
warnings.filterwarnings(
41944168
action='ignore',

0 commit comments

Comments
 (0)