Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion INSTALL.rst
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ Matplotlib requires the following dependencies:
* `pytz <http://pytz.sourceforge.net/>`__
* FreeType (>= 2.3)
* `cycler <http://matplotlib.org/cycler/>`__ (>= 0.10.0)
* `six <https://pypi.python.org/pypi/six>`_ (>= 1.10)
* `kiwisolver <https://github.com/nucleic/kiwi>`__ (>= 1.0.0)

Optionally, you can also install a number of packages to enable better user
Expand Down
7 changes: 0 additions & 7 deletions lib/matplotlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,6 @@
# NOTE: This file must remain Python 2 compatible for the foreseeable future,
# to ensure that we error out properly for existing editable installs.

import six

import sys
if sys.version_info < (3, 5): # noqa: E402
raise ImportError("""
Expand Down Expand Up @@ -197,11 +195,6 @@ def compare_versions(a, b):
raise ImportError("Matplotlib requires dateutil")


if not compare_versions(six.__version__, '1.10'):
raise ImportError(
"Matplotlib requires six>=1.10; you have %s" % six.__version__)


try:
import pyparsing
except ImportError:
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ def output_args(self):
def _init_from_registry(cls):
if sys.platform != 'win32' or rcParams[cls.exec_key] != 'convert':
return
from six.moves import winreg
import winreg
for flag in (0, winreg.KEY_WOW64_32KEY, winreg.KEY_WOW64_64KEY):
try:
hkey = winreg.OpenKeyEx(winreg.HKEY_LOCAL_MACHINE,
Expand Down
13 changes: 4 additions & 9 deletions lib/matplotlib/artist.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import six

from collections import OrderedDict, namedtuple
from functools import wraps
import inspect
Expand Down Expand Up @@ -286,7 +284,7 @@ def pchanged(self):
Fire an event when property changed, calling all of the
registered callbacks.
"""
for oid, func in six.iteritems(self._propobservers):
for oid, func in self._propobservers.items():
func(self)

def is_transform_set(self):
Expand Down Expand Up @@ -902,7 +900,7 @@ def set_label(self, s):
.. ACCEPTS: object
"""
if s is not None:
self._label = six.text_type(s)
self._label = str(s)
else:
self._label = None
self.pchanged()
Expand Down Expand Up @@ -1152,10 +1150,7 @@ def _get_setters_and_targets(self):
func = getattr(self.o, name)
if not callable(func):
continue
if six.PY2:
nargs = len(inspect.getargspec(func)[0])
else:
nargs = len(inspect.getfullargspec(func)[0])
nargs = len(inspect.getfullargspec(func).args)
if nargs < 2 or self.is_alias(func):
continue
source_class = self.o.__module__ + "." + self.o.__name__
Expand Down Expand Up @@ -1325,7 +1320,7 @@ def pprint_getters(self):
"""

lines = []
for name, val in sorted(six.iteritems(self.properties())):
for name, val in sorted(self.properties().items()):
if getattr(val, 'shape', ()) != () and len(val) > 6:
s = str(val[:6]) + '...'
else:
Expand Down
10 changes: 4 additions & 6 deletions lib/matplotlib/backend_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
The base class for the messaging area.
"""

import six

from contextlib import contextmanager
from functools import partial
import importlib
Expand Down Expand Up @@ -121,7 +119,7 @@ def get_registered_canvas_class(format):
if format not in _default_backends:
return None
backend_class = _default_backends[format]
if isinstance(backend_class, six.string_types):
if isinstance(backend_class, str):
backend_class = importlib.import_module(backend_class).FigureCanvas
_default_backends[format] = backend_class
return backend_class
Expand Down Expand Up @@ -2059,7 +2057,7 @@ def get_supported_filetypes_grouped(cls):
Experts Group', and the values are a list of filename extensions used
for that filetype, such as ['jpg', 'jpeg']."""
groupings = {}
for ext, name in six.iteritems(cls.filetypes):
for ext, name in cls.filetypes.items():
groupings.setdefault(name, []).append(ext)
groupings[name].sort()
return groupings
Expand Down Expand Up @@ -2130,11 +2128,11 @@ def print_figure(self, filename, dpi=None, facecolor=None, edgecolor=None,
# get format from filename, or from backend's default filetype
if isinstance(filename, getattr(os, "PathLike", ())):
filename = os.fspath(filename)
if isinstance(filename, six.string_types):
if isinstance(filename, str):
format = os.path.splitext(filename)[1][1:]
if format is None or format == '':
format = self.get_default_filetype()
if isinstance(filename, six.string_types):
if isinstance(filename, str):
filename = filename.rstrip('.') + '.' + format
format = format.lower()

Expand Down
29 changes: 13 additions & 16 deletions lib/matplotlib/backends/_backend_tk.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import six

import math
import logging
import os.path
Expand Down Expand Up @@ -58,14 +56,14 @@ def _restore_foreground_window_at_end():

def raise_msg_to_str(msg):
"""msg is a return arg from a raise. Join with new lines"""
if not isinstance(msg, six.string_types):
if not isinstance(msg, str):
msg = '\n'.join(map(str, msg))
return msg


def error_msg_tkpaint(msg, parent=None):
from six.moves import tkinter_messagebox as tkMessageBox
tkMessageBox.showerror("matplotlib", msg)
import tkinter.messagebox
tkinter.messagebox.showerror("matplotlib", msg)


def blit(photoimage, aggimage, offsets, bbox=None):
Expand Down Expand Up @@ -686,15 +684,15 @@ def configure_subplots(self):
window.grab_set()

def save_figure(self, *args):
from six.moves import tkinter_tkfiledialog, tkinter_messagebox
import tkinter.filedialog, tkinter.messagebox
filetypes = self.canvas.get_supported_filetypes().copy()
default_filetype = self.canvas.get_default_filetype()

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

# adding a default extension seems to break the
Expand All @@ -705,7 +703,7 @@ def save_figure(self, *args):
defaultextension = ''
initialdir = os.path.expanduser(rcParams['savefig.directory'])
initialfile = self.canvas.get_default_filename()
fname = tkinter_tkfiledialog.asksaveasfilename(
fname = tkinter.filedialog.asksaveasfilename(
master=self.window,
title='Save the figure',
filetypes=tk_filetypes,
Expand All @@ -719,12 +717,12 @@ def save_figure(self, *args):
# Save dir for next time, unless empty str (i.e., use cwd).
if initialdir != "":
rcParams['savefig.directory'] = (
os.path.dirname(six.text_type(fname)))
os.path.dirname(str(fname)))
try:
# This method will handle the delegation to the correct type
self.canvas.figure.savefig(fname)
except Exception as e:
tkinter_messagebox.showerror("Error saving file", str(e))
tkinter.messagebox.showerror("Error saving file", str(e))

def set_active(self, ind):
self._ind = ind
Expand Down Expand Up @@ -906,15 +904,15 @@ def set_message(self, s):

class SaveFigureTk(backend_tools.SaveFigureBase):
def trigger(self, *args):
from six.moves import tkinter_tkfiledialog, tkinter_messagebox
import tkinter.filedialog, tkinter.messagebox
filetypes = self.figure.canvas.get_supported_filetypes().copy()
default_filetype = self.figure.canvas.get_default_filetype()

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

# adding a default extension seems to break the
Expand All @@ -925,7 +923,7 @@ def trigger(self, *args):
defaultextension = ''
initialdir = os.path.expanduser(rcParams['savefig.directory'])
initialfile = self.figure.canvas.get_default_filename()
fname = tkinter_tkfiledialog.asksaveasfilename(
fname = tkinter.filedialog.asksaveasfilename(
master=self.figure.canvas.manager.window,
title='Save the figure',
filetypes=tk_filetypes,
Expand All @@ -942,13 +940,12 @@ def trigger(self, *args):
rcParams['savefig.directory'] = initialdir
else:
# save dir for next time
rcParams['savefig.directory'] = os.path.dirname(
six.text_type(fname))
rcParams['savefig.directory'] = os.path.dirname(str(fname))
try:
# This method will handle the delegation to the correct type
self.figure.savefig(fname)
except Exception as e:
tkinter_messagebox.showerror("Error saving file", str(e))
tkinter.messagebox.showerror("Error saving file", str(e))


class ConfigureSubplotsTk(backend_tools.ConfigureSubplotsBase):
Expand Down
2 changes: 0 additions & 2 deletions lib/matplotlib/backends/backend_agg.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
* integrate screen dpi w/ ppi and text

"""
import six

import threading
import numpy as np
from collections import OrderedDict
Expand Down
13 changes: 1 addition & 12 deletions lib/matplotlib/backends/backend_cairo.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
This backend depends on cairocffi or pycairo.
"""

import six

import copy
import gzip
import sys
Expand Down Expand Up @@ -395,13 +393,6 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
ctx.rotate(np.deg2rad(-angle))
ctx.set_font_size(size)

if HAS_CAIRO_CFFI:
if not isinstance(s, six.text_type):
s = six.text_type(s)
else:
if six.PY2 and isinstance(s, six.text_type):
s = s.encode("utf-8")

ctx.show_text(s)
ctx.restore()

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

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

for ox, oy, w, h in rects:
Expand Down Expand Up @@ -631,7 +620,7 @@ def _save(self, fo, fmt, **kwargs):
raise RuntimeError('cairo has not been compiled with SVG '
'support enabled')
if fmt == 'svgz':
if isinstance(fo, six.string_types):
if isinstance(fo, str):
fo = gzip.GzipFile(fo, 'wb')
else:
fo = gzip.GzipFile(None, 'wb', fileobj=fo)
Expand Down
26 changes: 9 additions & 17 deletions lib/matplotlib/backends/backend_ps.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
"""
A PostScript backend, which can produce both PostScript .ps and .eps
"""
import six
from six.moves import StringIO
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we not use StringIO in this module?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not anymore - it was only used in a isinstance check in a Python-2-only branch.


import glob, os, shutil, sys, time, datetime
import io
import logging
Expand Down Expand Up @@ -77,10 +74,7 @@ def gs_version(self):
s = subprocess.Popen(
[self.gs_exe, "--version"], stdout=subprocess.PIPE)
pipe, stderr = s.communicate()
if six.PY3:
ver = pipe.decode('ascii')
else:
ver = pipe
ver = pipe.decode('ascii')
try:
gs_version = tuple(map(int, ver.strip().split(".")))
except ValueError:
Expand Down Expand Up @@ -133,7 +127,7 @@ def _get_papertype(w, h):
return 'a0'

def _num_to_str(val):
if isinstance(val, six.string_types):
if isinstance(val, str):
return val

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

def merge_used_characters(self, other):
for stat_key, (realpath, charset) in six.iteritems(other):
for stat_key, (realpath, charset) in other.items():
used_characters = self.used_characters.setdefault(
stat_key, (realpath, set()))
used_characters[1].update(charset)
Expand Down Expand Up @@ -981,8 +975,7 @@ def _print_figure(
the key 'Creator' is used.
"""
isEPSF = format == 'eps'
if isinstance(outfile,
(six.string_types, getattr(os, "PathLike", ()),)):
if isinstance(outfile, (str, getattr(os, "PathLike", ()),)):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This getattr looks like another back-compat shim, how far back do we need this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

os.PathLike is new in Python 3.6, so it will be needed for a while yet.

outfile = title = getattr(os, "fspath", lambda obj: obj)(outfile)
title = title.encode("latin-1", "replace").decode()
passed_in_file_object = False
Expand Down Expand Up @@ -1102,8 +1095,8 @@ def print_figure_impl(fh):
for l in d.split('\n'):
print(l.strip(), file=fh)
if not rcParams['ps.useafm']:
for font_filename, chars in six.itervalues(
ps_renderer.used_characters):
for font_filename, chars in \
ps_renderer.used_characters.values():
if len(chars):
font = get_font(font_filename)
glyph_ids = []
Expand Down Expand Up @@ -1148,7 +1141,7 @@ def print_figure_impl(fh):

# write the figure
content = self._pswriter.getvalue()
if not isinstance(content, six.text_type):
if not isinstance(content, str):
content = content.decode('ascii')
print(content, file=fh)

Expand Down Expand Up @@ -1181,8 +1174,7 @@ def print_figure_impl(fh):
if passed_in_file_object:
requires_unicode = file_requires_unicode(outfile)

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

# Prevent the io.TextIOWrapper from closing the
Expand Down Expand Up @@ -1211,7 +1203,7 @@ def _print_figure_tex(
the key 'Creator' is used.
"""
isEPSF = format == 'eps'
if isinstance(outfile, six.string_types):
if isinstance(outfile, str):
title = outfile
elif is_writable_file_like(outfile):
title = None
Expand Down
Loading