6
6
it imports matplotlib only at runtime.
7
7
"""
8
8
9
- import six
10
- from six .moves import xrange , zip
11
9
import collections
12
10
import contextlib
13
11
import datetime
@@ -57,9 +55,9 @@ def unicode_safe(s):
57
55
preferredencoding = None
58
56
59
57
if preferredencoding is None :
60
- return six . text_type (s )
58
+ return str (s )
61
59
else :
62
- return six . text_type (s , preferredencoding )
60
+ return str (s , preferredencoding )
63
61
return s
64
62
65
63
@@ -81,18 +79,11 @@ def __init__(self, cb):
81
79
self ._destroy_callbacks = []
82
80
try :
83
81
try :
84
- if six .PY3 :
85
- self .inst = ref (cb .__self__ , self ._destroy )
86
- else :
87
- self .inst = ref (cb .im_self , self ._destroy )
82
+ self .inst = ref (cb .__self__ , self ._destroy )
88
83
except TypeError :
89
84
self .inst = None
90
- if six .PY3 :
91
- self .func = cb .__func__
92
- self .klass = cb .__self__ .__class__
93
- else :
94
- self .func = cb .im_func
95
- self .klass = cb .im_class
85
+ self .func = cb .__func__
86
+ self .klass = cb .__self__ .__class__
96
87
except AttributeError :
97
88
self .inst = None
98
89
self .func = cb
@@ -158,12 +149,6 @@ def __eq__(self, other):
158
149
except Exception :
159
150
return False
160
151
161
- def __ne__ (self , other ):
162
- """
163
- Inverse of __eq__.
164
- """
165
- return not self .__eq__ (other )
166
-
167
152
def __hash__ (self ):
168
153
return self ._hash
169
154
@@ -267,7 +252,7 @@ def connect(self, s, func):
267
252
return cid
268
253
269
254
def _remove_proxy (self , proxy ):
270
- for signal , proxies in list (six . iteritems ( self ._func_cid_map )):
255
+ for signal , proxies in list (self ._func_cid_map . items ( )):
271
256
try :
272
257
del self .callbacks [signal ][proxies [proxy ]]
273
258
except KeyError :
@@ -280,15 +265,14 @@ def _remove_proxy(self, proxy):
280
265
def disconnect (self , cid ):
281
266
"""Disconnect the callback registered with callback id *cid*.
282
267
"""
283
- for eventname , callbackd in list (six . iteritems ( self .callbacks )):
268
+ for eventname , callbackd in list (self .callbacks . items ( )):
284
269
try :
285
270
del callbackd [cid ]
286
271
except KeyError :
287
272
continue
288
273
else :
289
- for signal , functions in list (
290
- six .iteritems (self ._func_cid_map )):
291
- for function , value in list (six .iteritems (functions )):
274
+ for signal , functions in list (self ._func_cid_map .items ()):
275
+ for function , value in list (functions .items ()):
292
276
if value == cid :
293
277
del functions [function ]
294
278
return
@@ -301,7 +285,7 @@ def process(self, s, *args, **kwargs):
301
285
called with ``*args`` and ``**kwargs``.
302
286
"""
303
287
if s in self .callbacks :
304
- for cid , proxy in list (six . iteritems ( self .callbacks [s ])):
288
+ for cid , proxy in list (self .callbacks [s ]. items ( )):
305
289
try :
306
290
proxy (* args , ** kwargs )
307
291
except ReferenceError :
@@ -471,7 +455,7 @@ def to_filehandle(fname, flag='rU', return_opened=False, encoding=None):
471
455
return to_filehandle (
472
456
os .fspath (fname ),
473
457
flag = flag , return_opened = return_opened , encoding = encoding )
474
- if isinstance (fname , six . string_types ):
458
+ if isinstance (fname , str ):
475
459
if fname .endswith ('.gz' ):
476
460
# get rid of 'U' in flag for gzipped files.
477
461
flag = flag .replace ('U' , '' )
@@ -509,12 +493,12 @@ def open_file_cm(path_or_file, mode="r", encoding=None):
509
493
510
494
def is_scalar_or_string (val ):
511
495
"""Return whether the given object is a scalar or string like."""
512
- return isinstance (val , six . string_types ) or not iterable (val )
496
+ return isinstance (val , str ) or not iterable (val )
513
497
514
498
515
499
def _string_to_bool (s ):
516
500
"""Parses the string argument as a boolean"""
517
- if not isinstance (s , six . string_types ):
501
+ if not isinstance (s , str ):
518
502
return bool (s )
519
503
warn_deprecated ("2.2" , "Passing one of 'on', 'true', 'off', 'false' as a "
520
504
"boolean is deprecated; use an actual boolean "
@@ -593,14 +577,7 @@ def mkdirs(newdir, mode=0o777):
593
577
"""
594
578
# this functionality is now in core python as of 3.2
595
579
# LPY DROP
596
- if six .PY3 :
597
- os .makedirs (newdir , mode = mode , exist_ok = True )
598
- else :
599
- try :
600
- os .makedirs (newdir , mode = mode )
601
- except OSError as exception :
602
- if exception .errno != errno .EEXIST :
603
- raise
580
+ os .makedirs (newdir , mode = mode , exist_ok = True )
604
581
605
582
606
583
@deprecated ('3.0' )
@@ -921,7 +898,7 @@ def print_path(path):
921
898
922
899
outstream .write (" %s -- " % type (step ))
923
900
if isinstance (step , dict ):
924
- for key , val in six . iteritems ( step ):
901
+ for key , val in step . items ( ):
925
902
if val is next :
926
903
outstream .write ("[{!r}]" .format (key ))
927
904
break
@@ -1072,13 +1049,13 @@ def __iter__(self):
1072
1049
1073
1050
# Mark each group as we come across if by appending a token,
1074
1051
# and don't yield it twice
1075
- for group in six . itervalues ( self ._mapping ):
1052
+ for group in self ._mapping . values ( ):
1076
1053
if group [- 1 ] is not token :
1077
1054
yield [x () for x in group ]
1078
1055
group .append (token )
1079
1056
1080
1057
# Cleanup the tokens
1081
- for group in six . itervalues ( self ._mapping ):
1058
+ for group in self ._mapping . values ( ):
1082
1059
if group [- 1 ] is token :
1083
1060
del group [- 1 ]
1084
1061
@@ -1149,14 +1126,13 @@ def delete_masked_points(*args):
1149
1126
"""
1150
1127
if not len (args ):
1151
1128
return ()
1152
- if ( isinstance (args [0 ], six . string_types ) or not iterable (args [0 ]) ):
1129
+ if isinstance (args [0 ], str ) or not iterable (args [0 ]):
1153
1130
raise ValueError ("First argument must be a sequence" )
1154
1131
nrecs = len (args [0 ])
1155
1132
margs = []
1156
1133
seqlist = [False ] * len (args )
1157
1134
for i , x in enumerate (args ):
1158
- if (not isinstance (x , six .string_types ) and iterable (x )
1159
- and len (x ) == nrecs ):
1135
+ if not isinstance (x , str ) and iterable (x ) and len (x ) == nrecs :
1160
1136
seqlist [i ] = True
1161
1137
if isinstance (x , np .ma .MaskedArray ):
1162
1138
if x .ndim > 1 :
@@ -1313,7 +1289,7 @@ def _compute_conf_interval(data, med, iqr, bootstrap):
1313
1289
raise ValueError ("Dimensions of labels and X must be compatible" )
1314
1290
1315
1291
input_whis = whis
1316
- for ii , (x , label ) in enumerate (zip (X , labels ), start = 0 ):
1292
+ for ii , (x , label ) in enumerate (zip (X , labels )):
1317
1293
1318
1294
# empty dict
1319
1295
stats = {}
@@ -1403,7 +1379,7 @@ def _compute_conf_interval(data, med, iqr, bootstrap):
1403
1379
# The ls_mapper maps short codes for line style to their full name used by
1404
1380
# backends; the reverse mapper is for mapping full names to short ones.
1405
1381
ls_mapper = {'-' : 'solid' , '--' : 'dashed' , '-.' : 'dashdot' , ':' : 'dotted' }
1406
- ls_mapper_r = {v : k for k , v in six . iteritems ( ls_mapper )}
1382
+ ls_mapper_r = {v : k for k , v in ls_mapper . items ( )}
1407
1383
1408
1384
1409
1385
@deprecated ('2.2' )
@@ -1480,16 +1456,9 @@ def contiguous_regions(mask):
1480
1456
def is_math_text (s ):
1481
1457
# Did we find an even number of non-escaped dollar signs?
1482
1458
# If so, treat is as math text.
1483
- try :
1484
- s = six .text_type (s )
1485
- except UnicodeDecodeError :
1486
- raise ValueError (
1487
- "matplotlib display text must have all code points < 128 or use "
1488
- "Unicode strings" )
1489
-
1459
+ s = str (s )
1490
1460
dollar_count = s .count (r'$' ) - s .count (r'\$' )
1491
1461
even_dollars = (dollar_count > 0 and dollar_count % 2 == 0 )
1492
-
1493
1462
return even_dollars
1494
1463
1495
1464
@@ -1833,7 +1802,7 @@ def normalize_kwargs(kw, alias_mapping=None, required=(), forbidden=(),
1833
1802
ret = dict ()
1834
1803
1835
1804
# hit all alias mappings
1836
- for canonical , alias_list in six . iteritems ( alias_mapping ):
1805
+ for canonical , alias_list in alias_mapping . items ( ):
1837
1806
1838
1807
# the alias lists are ordered from lowest to highest priority
1839
1808
# so we know to use the last value in this list
@@ -1879,11 +1848,10 @@ def normalize_kwargs(kw, alias_mapping=None, required=(), forbidden=(),
1879
1848
allowed_set = set (required ) | set (allowed )
1880
1849
fail_keys = [k for k in ret if k not in allowed_set ]
1881
1850
if fail_keys :
1882
- raise TypeError ("kwargs contains {keys!r} which are not in "
1883
- "the required {req!r} or "
1884
- "allowed {allow!r} keys" .format (
1885
- keys = fail_keys , req = required ,
1886
- allow = allowed ))
1851
+ raise TypeError (
1852
+ "kwargs contains {keys!r} which are not in the required "
1853
+ "{req!r} or allowed {allow!r} keys" .format (
1854
+ keys = fail_keys , req = required , allow = allowed ))
1887
1855
1888
1856
return ret
1889
1857
@@ -2014,7 +1982,7 @@ def _str_equal(obj, s):
2014
1982
because in such cases, a naive ``obj == s`` would yield an array, which
2015
1983
cannot be used in a boolean context.
2016
1984
"""
2017
- return isinstance (obj , six . string_types ) and obj == s
1985
+ return isinstance (obj , str ) and obj == s
2018
1986
2019
1987
2020
1988
def _str_lower_equal (obj , s ):
@@ -2024,7 +1992,7 @@ def _str_lower_equal(obj, s):
2024
1992
because in such cases, a naive ``obj == s`` would yield an array, which
2025
1993
cannot be used in a boolean context.
2026
1994
"""
2027
- return isinstance (obj , six . string_types ) and obj .lower () == s
1995
+ return isinstance (obj , str ) and obj .lower () == s
2028
1996
2029
1997
2030
1998
def _define_aliases (alias_d , cls = None ):
0 commit comments