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

Skip to content

Commit 8168210

Browse files
Zac-HDjklymak
authored andcommitted
Remove dependency on six - we're Py3 only now! (#11158)
* Remove no-op imports of `six` * Strip out obsolete compatibility layer from `six` * Deprecate now-useless functions * Do not install `six` on py3-only version * Final edits for anntzer's review
1 parent d2968e6 commit 8168210

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+163
-388
lines changed

INSTALL.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ Matplotlib requires the following dependencies:
142142
* `pytz <http://pytz.sourceforge.net/>`__
143143
* FreeType (>= 2.3)
144144
* `cycler <http://matplotlib.org/cycler/>`__ (>= 0.10.0)
145-
* `six <https://pypi.python.org/pypi/six>`_ (>= 1.10)
146145
* `kiwisolver <https://github.com/nucleic/kiwi>`__ (>= 1.0.0)
147146

148147
Optionally, you can also install a number of packages to enable better user

lib/matplotlib/__init__.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,6 @@
102102
# NOTE: This file must remain Python 2 compatible for the foreseeable future,
103103
# to ensure that we error out properly for existing editable installs.
104104

105-
import six
106-
107105
import sys
108106
if sys.version_info < (3, 5): # noqa: E402
109107
raise ImportError("""
@@ -197,11 +195,6 @@ def compare_versions(a, b):
197195
raise ImportError("Matplotlib requires dateutil")
198196

199197

200-
if not compare_versions(six.__version__, '1.10'):
201-
raise ImportError(
202-
"Matplotlib requires six>=1.10; you have %s" % six.__version__)
203-
204-
205198
try:
206199
import pyparsing
207200
except ImportError:

lib/matplotlib/animation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,7 @@ def output_args(self):
727727
def _init_from_registry(cls):
728728
if sys.platform != 'win32' or rcParams[cls.exec_key] != 'convert':
729729
return
730-
from six.moves import winreg
730+
import winreg
731731
for flag in (0, winreg.KEY_WOW64_32KEY, winreg.KEY_WOW64_64KEY):
732732
try:
733733
hkey = winreg.OpenKeyEx(winreg.HKEY_LOCAL_MACHINE,

lib/matplotlib/artist.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import six
2-
31
from collections import OrderedDict, namedtuple
42
from functools import wraps
53
import inspect
@@ -286,7 +284,7 @@ def pchanged(self):
286284
Fire an event when property changed, calling all of the
287285
registered callbacks.
288286
"""
289-
for oid, func in six.iteritems(self._propobservers):
287+
for oid, func in self._propobservers.items():
290288
func(self)
291289

292290
def is_transform_set(self):
@@ -902,7 +900,7 @@ def set_label(self, s):
902900
.. ACCEPTS: object
903901
"""
904902
if s is not None:
905-
self._label = six.text_type(s)
903+
self._label = str(s)
906904
else:
907905
self._label = None
908906
self.pchanged()
@@ -1152,10 +1150,7 @@ def _get_setters_and_targets(self):
11521150
func = getattr(self.o, name)
11531151
if not callable(func):
11541152
continue
1155-
if six.PY2:
1156-
nargs = len(inspect.getargspec(func)[0])
1157-
else:
1158-
nargs = len(inspect.getfullargspec(func)[0])
1153+
nargs = len(inspect.getfullargspec(func).args)
11591154
if nargs < 2 or self.is_alias(func):
11601155
continue
11611156
source_class = self.o.__module__ + "." + self.o.__name__
@@ -1325,7 +1320,7 @@ def pprint_getters(self):
13251320
"""
13261321

13271322
lines = []
1328-
for name, val in sorted(six.iteritems(self.properties())):
1323+
for name, val in sorted(self.properties().items()):
13291324
if getattr(val, 'shape', ()) != () and len(val) > 6:
13301325
s = str(val[:6]) + '...'
13311326
else:

lib/matplotlib/backend_bases.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@
3232
The base class for the messaging area.
3333
"""
3434

35-
import six
36-
3735
from contextlib import contextmanager
3836
from functools import partial
3937
import importlib
@@ -121,7 +119,7 @@ def get_registered_canvas_class(format):
121119
if format not in _default_backends:
122120
return None
123121
backend_class = _default_backends[format]
124-
if isinstance(backend_class, six.string_types):
122+
if isinstance(backend_class, str):
125123
backend_class = importlib.import_module(backend_class).FigureCanvas
126124
_default_backends[format] = backend_class
127125
return backend_class
@@ -2059,7 +2057,7 @@ def get_supported_filetypes_grouped(cls):
20592057
Experts Group', and the values are a list of filename extensions used
20602058
for that filetype, such as ['jpg', 'jpeg']."""
20612059
groupings = {}
2062-
for ext, name in six.iteritems(cls.filetypes):
2060+
for ext, name in cls.filetypes.items():
20632061
groupings.setdefault(name, []).append(ext)
20642062
groupings[name].sort()
20652063
return groupings
@@ -2130,11 +2128,11 @@ def print_figure(self, filename, dpi=None, facecolor=None, edgecolor=None,
21302128
# get format from filename, or from backend's default filetype
21312129
if isinstance(filename, getattr(os, "PathLike", ())):
21322130
filename = os.fspath(filename)
2133-
if isinstance(filename, six.string_types):
2131+
if isinstance(filename, str):
21342132
format = os.path.splitext(filename)[1][1:]
21352133
if format is None or format == '':
21362134
format = self.get_default_filetype()
2137-
if isinstance(filename, six.string_types):
2135+
if isinstance(filename, str):
21382136
filename = filename.rstrip('.') + '.' + format
21392137
format = format.lower()
21402138

lib/matplotlib/backends/_backend_tk.py

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import six
2-
31
import math
42
import logging
53
import os.path
@@ -58,14 +56,14 @@ def _restore_foreground_window_at_end():
5856

5957
def raise_msg_to_str(msg):
6058
"""msg is a return arg from a raise. Join with new lines"""
61-
if not isinstance(msg, six.string_types):
59+
if not isinstance(msg, str):
6260
msg = '\n'.join(map(str, msg))
6361
return msg
6462

6563

6664
def error_msg_tkpaint(msg, parent=None):
67-
from six.moves import tkinter_messagebox as tkMessageBox
68-
tkMessageBox.showerror("matplotlib", msg)
65+
import tkinter.messagebox
66+
tkinter.messagebox.showerror("matplotlib", msg)
6967

7068

7169
def blit(photoimage, aggimage, offsets, bbox=None):
@@ -686,15 +684,15 @@ def configure_subplots(self):
686684
window.grab_set()
687685

688686
def save_figure(self, *args):
689-
from six.moves import tkinter_tkfiledialog, tkinter_messagebox
687+
import tkinter.filedialog, tkinter.messagebox
690688
filetypes = self.canvas.get_supported_filetypes().copy()
691689
default_filetype = self.canvas.get_default_filetype()
692690

693691
# Tk doesn't provide a way to choose a default filetype,
694692
# so we just have to put it first
695693
default_filetype_name = filetypes.pop(default_filetype)
696694
sorted_filetypes = ([(default_filetype, default_filetype_name)]
697-
+ sorted(six.iteritems(filetypes)))
695+
+ sorted(filetypes.items()))
698696
tk_filetypes = [(name, '*.%s' % ext) for ext, name in sorted_filetypes]
699697

700698
# adding a default extension seems to break the
@@ -705,7 +703,7 @@ def save_figure(self, *args):
705703
defaultextension = ''
706704
initialdir = os.path.expanduser(rcParams['savefig.directory'])
707705
initialfile = self.canvas.get_default_filename()
708-
fname = tkinter_tkfiledialog.asksaveasfilename(
706+
fname = tkinter.filedialog.asksaveasfilename(
709707
master=self.window,
710708
title='Save the figure',
711709
filetypes=tk_filetypes,
@@ -719,12 +717,12 @@ def save_figure(self, *args):
719717
# Save dir for next time, unless empty str (i.e., use cwd).
720718
if initialdir != "":
721719
rcParams['savefig.directory'] = (
722-
os.path.dirname(six.text_type(fname)))
720+
os.path.dirname(str(fname)))
723721
try:
724722
# This method will handle the delegation to the correct type
725723
self.canvas.figure.savefig(fname)
726724
except Exception as e:
727-
tkinter_messagebox.showerror("Error saving file", str(e))
725+
tkinter.messagebox.showerror("Error saving file", str(e))
728726

729727
def set_active(self, ind):
730728
self._ind = ind
@@ -906,15 +904,15 @@ def set_message(self, s):
906904

907905
class SaveFigureTk(backend_tools.SaveFigureBase):
908906
def trigger(self, *args):
909-
from six.moves import tkinter_tkfiledialog, tkinter_messagebox
907+
import tkinter.filedialog, tkinter.messagebox
910908
filetypes = self.figure.canvas.get_supported_filetypes().copy()
911909
default_filetype = self.figure.canvas.get_default_filetype()
912910

913911
# Tk doesn't provide a way to choose a default filetype,
914912
# so we just have to put it first
915913
default_filetype_name = filetypes.pop(default_filetype)
916914
sorted_filetypes = ([(default_filetype, default_filetype_name)]
917-
+ sorted(six.iteritems(filetypes)))
915+
+ sorted(filetypes.items()))
918916
tk_filetypes = [(name, '*.%s' % ext) for ext, name in sorted_filetypes]
919917

920918
# adding a default extension seems to break the
@@ -925,7 +923,7 @@ def trigger(self, *args):
925923
defaultextension = ''
926924
initialdir = os.path.expanduser(rcParams['savefig.directory'])
927925
initialfile = self.figure.canvas.get_default_filename()
928-
fname = tkinter_tkfiledialog.asksaveasfilename(
926+
fname = tkinter.filedialog.asksaveasfilename(
929927
master=self.figure.canvas.manager.window,
930928
title='Save the figure',
931929
filetypes=tk_filetypes,
@@ -942,13 +940,12 @@ def trigger(self, *args):
942940
rcParams['savefig.directory'] = initialdir
943941
else:
944942
# save dir for next time
945-
rcParams['savefig.directory'] = os.path.dirname(
946-
six.text_type(fname))
943+
rcParams['savefig.directory'] = os.path.dirname(str(fname))
947944
try:
948945
# This method will handle the delegation to the correct type
949946
self.figure.savefig(fname)
950947
except Exception as e:
951-
tkinter_messagebox.showerror("Error saving file", str(e))
948+
tkinter.messagebox.showerror("Error saving file", str(e))
952949

953950

954951
class ConfigureSubplotsTk(backend_tools.ConfigureSubplotsBase):

lib/matplotlib/backends/backend_agg.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
* integrate screen dpi w/ ppi and text
2020
2121
"""
22-
import six
23-
2422
import threading
2523
import numpy as np
2624
from collections import OrderedDict

lib/matplotlib/backends/backend_cairo.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
This backend depends on cairocffi or pycairo.
77
"""
88

9-
import six
10-
119
import copy
1210
import gzip
1311
import sys
@@ -395,13 +393,6 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
395393
ctx.rotate(np.deg2rad(-angle))
396394
ctx.set_font_size(size)
397395

398-
if HAS_CAIRO_CFFI:
399-
if not isinstance(s, six.text_type):
400-
s = six.text_type(s)
401-
else:
402-
if six.PY2 and isinstance(s, six.text_type):
403-
s = s.encode("utf-8")
404-
405396
ctx.show_text(s)
406397
ctx.restore()
407398

@@ -426,8 +417,6 @@ def _draw_mathtext(self, gc, x, y, s, prop, angle):
426417

427418
size = fontsize * self.dpi / 72.0
428419
ctx.set_font_size(size)
429-
if not six.PY3 and isinstance(s, six.text_type):
430-
s = s.encode("utf-8")
431420
ctx.show_text(s)
432421

433422
for ox, oy, w, h in rects:
@@ -631,7 +620,7 @@ def _save(self, fo, fmt, **kwargs):
631620
raise RuntimeError('cairo has not been compiled with SVG '
632621
'support enabled')
633622
if fmt == 'svgz':
634-
if isinstance(fo, six.string_types):
623+
if isinstance(fo, str):
635624
fo = gzip.GzipFile(fo, 'wb')
636625
else:
637626
fo = gzip.GzipFile(None, 'wb', fileobj=fo)

lib/matplotlib/backends/backend_ps.py

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
"""
22
A PostScript backend, which can produce both PostScript .ps and .eps
33
"""
4-
import six
5-
from six.moves import StringIO
6-
74
import glob, os, shutil, sys, time, datetime
85
import io
96
import logging
@@ -77,10 +74,7 @@ def gs_version(self):
7774
s = subprocess.Popen(
7875
[self.gs_exe, "--version"], stdout=subprocess.PIPE)
7976
pipe, stderr = s.communicate()
80-
if six.PY3:
81-
ver = pipe.decode('ascii')
82-
else:
83-
ver = pipe
77+
ver = pipe.decode('ascii')
8478
try:
8579
gs_version = tuple(map(int, ver.strip().split(".")))
8680
except ValueError:
@@ -133,7 +127,7 @@ def _get_papertype(w, h):
133127
return 'a0'
134128

135129
def _num_to_str(val):
136-
if isinstance(val, six.string_types):
130+
if isinstance(val, str):
137131
return val
138132

139133
ival = int(val)
@@ -229,7 +223,7 @@ def track_characters(self, font, s):
229223
used_characters[1].update(map(ord, s))
230224

231225
def merge_used_characters(self, other):
232-
for stat_key, (realpath, charset) in six.iteritems(other):
226+
for stat_key, (realpath, charset) in other.items():
233227
used_characters = self.used_characters.setdefault(
234228
stat_key, (realpath, set()))
235229
used_characters[1].update(charset)
@@ -981,8 +975,7 @@ def _print_figure(
981975
the key 'Creator' is used.
982976
"""
983977
isEPSF = format == 'eps'
984-
if isinstance(outfile,
985-
(six.string_types, getattr(os, "PathLike", ()),)):
978+
if isinstance(outfile, (str, getattr(os, "PathLike", ()),)):
986979
outfile = title = getattr(os, "fspath", lambda obj: obj)(outfile)
987980
title = title.encode("latin-1", "replace").decode()
988981
passed_in_file_object = False
@@ -1102,8 +1095,8 @@ def print_figure_impl(fh):
11021095
for l in d.split('\n'):
11031096
print(l.strip(), file=fh)
11041097
if not rcParams['ps.useafm']:
1105-
for font_filename, chars in six.itervalues(
1106-
ps_renderer.used_characters):
1098+
for font_filename, chars in \
1099+
ps_renderer.used_characters.values():
11071100
if len(chars):
11081101
font = get_font(font_filename)
11091102
glyph_ids = []
@@ -1148,7 +1141,7 @@ def print_figure_impl(fh):
11481141

11491142
# write the figure
11501143
content = self._pswriter.getvalue()
1151-
if not isinstance(content, six.text_type):
1144+
if not isinstance(content, str):
11521145
content = content.decode('ascii')
11531146
print(content, file=fh)
11541147

@@ -1181,8 +1174,7 @@ def print_figure_impl(fh):
11811174
if passed_in_file_object:
11821175
requires_unicode = file_requires_unicode(outfile)
11831176

1184-
if (not requires_unicode and
1185-
(six.PY3 or not isinstance(outfile, StringIO))):
1177+
if not requires_unicode:
11861178
fh = io.TextIOWrapper(outfile, encoding="latin-1")
11871179

11881180
# Prevent the io.TextIOWrapper from closing the
@@ -1211,7 +1203,7 @@ def _print_figure_tex(
12111203
the key 'Creator' is used.
12121204
"""
12131205
isEPSF = format == 'eps'
1214-
if isinstance(outfile, six.string_types):
1206+
if isinstance(outfile, str):
12151207
title = outfile
12161208
elif is_writable_file_like(outfile):
12171209
title = None

0 commit comments

Comments
 (0)