Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Make cbook safe to import while removing duplicate is_string_like; #1762

Merged
merged 2 commits into from

3 participants

@efiring
Owner

closes #1019, replaces #1662.

lib/matplotlib/cbook.py
@@ -1,6 +1,14 @@
"""
A collection of utility functions and classes. Many (but not all)
-from the Python Cookbook -- hence the name cbook
+from the Python Cookbook -- hence the name cbook.
+
+This module is in transition, with the intention of migrating
@pelson Collaborator
pelson added a note

This paragraph is the only potential bone of contention for me. Has there been general agreement on transitioning cbook? FWIW I've read #1647 and the relevant mailing list discussion and still haven't found a definitive strategy - personally, I think anything of that scale should be covered by a MEP with a full transition plan.

On the basis of my comments, I wonder if we are better off not pre-empting that work here, and simply removing this paragraph?

@NelleV Collaborator
NelleV added a note

Moving the methods to a newly named module is debattable, but I think deprecating unused methods should still be done. I'm a a bit swamped with work right now, but I'll submit a new PR soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@pelson
Collaborator

Other than my comment, :+1:

@efiring efiring Update lib/matplotlib/cbook.py
Simplify module docstring, removing mention of possible future changes.
fb56db1
@efiring efiring merged commit 433da1a into from
@efiring efiring deleted the branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 18, 2013
  1. @efiring
Commits on Feb 19, 2013
  1. @efiring

    Update lib/matplotlib/cbook.py

    efiring authored
    Simplify module docstring, removing mention of possible future changes.
This page is out of date. Refresh to see the latest.
Showing with 29 additions and 25 deletions.
  1. +5 −19 lib/matplotlib/__init__.py
  2. +24 −6 lib/matplotlib/cbook.py
View
24 lib/matplotlib/__init__.py
@@ -106,6 +106,11 @@
import distutils.sysconfig
import distutils.version
+# cbook must import matplotlib only within function
+# definitions, so it is safe to import from it here.
+from matplotlib.cbook import MatplotlibDeprecationWarning
+from matplotlib.cbook import is_string_like
+
try:
reload
except NameError:
@@ -123,19 +128,6 @@
sys.argv = ['modpython']
-class MatplotlibDeprecationWarning(UserWarning):
- """
- A class for issuing deprecation warnings for Matplotlib users.
-
- In light of the fact that Python builtin DeprecationWarnings are ignored
- by default as of Python 2.7 (see link below), this class was put in to
- allow for the signaling of deprecation, but via UserWarnings which are not
- ignored by default.
-
- http://docs.python.org/dev/whatsnew/2.7.html#the-future-for-python-2-x
- """
- pass
-
"""
Manage user customizations through a rc file.
@@ -192,12 +184,6 @@ def byte2str(b): return b
__version__numpy__, numpy.__version__))
del version
-def is_string_like(obj):
- if hasattr(obj, 'shape'): return 0
- try: obj + ''
- except (TypeError, ValueError): return 0
- return 1
-
def _is_writable_dir(p):
"""
View
30 lib/matplotlib/cbook.py
@@ -1,7 +1,11 @@
"""
-A collection of utility functions and classes. Many (but not all)
-from the Python Cookbook -- hence the name cbook
+A collection of utility functions and classes. Originally, many
+(but not all) were from the Python Cookbook -- hence the name cbook.
+
+This module is safe to import from anywhere within matplotlib;
+it imports matplotlib only at runtime.
"""
+
from __future__ import print_function
import datetime
@@ -18,18 +22,28 @@
import threading
import time
import traceback
+import types
import warnings
from weakref import ref, WeakKeyDictionary
-import matplotlib
-from matplotlib import MatplotlibDeprecationWarning as mplDeprecation
-
import numpy as np
import numpy.ma as ma
-import types
+class MatplotlibDeprecationWarning(UserWarning):
+ """
+ A class for issuing deprecation warnings for Matplotlib users.
+ In light of the fact that Python builtin DeprecationWarnings are ignored
+ by default as of Python 2.7 (see link below), this class was put in to
+ allow for the signaling of deprecation, but via UserWarnings which are not
+ ignored by default.
+
+ http://docs.python.org/dev/whatsnew/2.7.html#the-future-for-python-2-x
+ """
+ pass
+
+mplDeprecation = MatplotlibDeprecationWarning
# On some systems, locale.getpreferredencoding returns None,
# which can break unicode; and the sage project reports that
@@ -42,6 +56,8 @@
if sys.version_info[0] >= 3:
def unicode_safe(s):
+ import matplotlib
+
try:
preferredencoding = locale.getpreferredencoding(
matplotlib.rcParams['axes.formatter.use_locale']).strip()
@@ -576,6 +592,8 @@ def get_sample_data(fname, asfileobj=True):
If the filename ends in .gz, the file is implicitly ungzipped.
"""
+ import matplotlib
+
if matplotlib.rcParams['examples.directory']:
root = matplotlib.rcParams['examples.directory']
else:
Something went wrong with that request. Please try again.