Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

is_string_like existed both in matplotlib and matplotlib.cbook #1662

Closed
wants to merge 2 commits into from
Closed

is_string_like existed both in matplotlib and matplotlib.cbook #1662

wants to merge 2 commits into from

Conversation

NelleV
Copy link
Member

@NelleV NelleV commented Jan 15, 2013

This closes #1019.

is_string_like existed both in matplotlib and in matplotlib.cbook. The proposed fix was to remove is_string_like from cbook and import the one from matplotlib in cbook. I'm somewhat unsatisfied with this solution, but backward compatibility is completely maintained, and it is better than what existed before (code duplication).

except (TypeError, ValueError): return 0
return 1
"""Return True if *obj* looks like a string"""
if isinstance(obj, (str, unicode)):
Copy link
Member

Choose a reason for hiding this comment

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

is using basestring as the baseclass not preferred?

@mdboom
Copy link
Member

mdboom commented Jan 15, 2013

Careful: basestring is not available on Python 3.x, and 2to3 converts it to merely str. This is decidedly not the behavior we want. Best to revert this to isinstance(x, (bytes, unicode)) and add a comment about why we aren't using basestring.

@NelleV
Copy link
Member Author

NelleV commented Jan 15, 2013

I've got problems with the code right now. The proposed fix might not work because of circular imports.

I'll revert back to str and unicode, and add the comment.

@NelleV
Copy link
Member Author

NelleV commented Jan 16, 2013

So, indeed I have a circular import in my current fix (cbook <- matplotlib <- rcsetup <- colors <- cbook).

I think it is problematic that the "utils" module (cbook) relies on importing matplotlib: this means it cannot be imported everywhere (in particular, in matplotlib.__init__). I think the safest way to proceed would be to split cbook into two: a part that depends on matplotlib for the rcparams dependency, and the rest in another file (including, all the validation methods which are needed in most of the modules). Another way to fix the problem would be to have the module rcsetup not relying on another module (here, colors), hence having matplotlib importable from any submodule of matplotlib.

Thoughts? Maybe this discussion should move on the mailing list, where more people could give their insights on the problem ?

@efiring
Copy link
Member

efiring commented Feb 18, 2013

I think #1762 solves the problem, so I am closing this.

@efiring efiring closed this Feb 18, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Repeated is_string_like function
4 participants