-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Replaced noqa-comments by using Axes3D.name instead of '3d' for proje… #12249
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
Conversation
…ction parameters.
There was a mention of this before, but it was never decided upon: #11651 (comment) |
@folkol Thanks for bringing up the topic. Improving the style of the examples is really valuable. I support getting rid of However, whether to use Let's just exclude F401 in all examples from the mplot3d section of the gallery via Note: For our internal code, I propose to leave the |
We could also look into possibly utilizing a pluggy approach to registering
axes subtypes so that importing Axes3d wouldn't be needed anymore.
…On Mon, Sep 24, 2018 at 6:20 PM Tim Hoffmann ***@***.***> wrote:
@folkol <https://github.com/folkol> Thanks for bringing up the topic.
Improving the style of the examples is really valuable. I support getting
rid of # noqa in the examples because it might confuse people.
However, whether to use projection='3d' or projection=Axes3D.name should
only be determined by what we want the users to actually use in their code.
And I'm -1 on projection=Axes3D.name. It's less readable and less clear.
Let's just exclude F401 in all examples from the mplot3d section of the
gallery via .flake8.
Note: For our internal code, I propose to leave the # noqa in place
because this narrows the scope to exactly that import.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#12249 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AARy-GUSbH4XRMsyCMhYZ5vE-SkZfjTfks5ueVqlgaJpZM4W2nBJ>
.
|
Yeah, the change is 100% a workaround for tooling issues — which sucks. I think that it is for the better, though (as long as the examples must pass a linter). I also agree with @tacaswell on the 50/50 part. Maybe running the linter with global ignores for the example files would be even better? (With the risk of missing actual errors in the process.) |
does |
From a code style point of view In the end, a plugin approach for the 3d Axes would be best. Importing Axes3D to make 3D Axes work is the original workaround, which drags all the other workarounds along. However, I'm afraid that's a bit more work (haven't looked into the details). |
It's a longstanding python convention that assigning to _ means "I syntactically need to assign this to something, but I don't care". Doing the same for imports doesn't seem too big of a stretch. OTOH we could also just always register Axes3D by default, it's not clear to me why we don't (beyond the hypothetical case of allowing installs of matplotlib that don't include mpl_toolkits, but 1) I don't think we should actually bother to allow that, and 2) even if we really do we can just wrap the registration in a try... except ImportError). |
The general notion for _ is well known. However I've never seen it used for imports. And indeed google has three results for searching
One of which is pylint, which ignores this since pylint 1.7 I'm fine with default-registering Axes3D. |
Would it make sense to allow |
I don't think so, @eric-wieser, the parameter expects a |
I'd say the inverse - why convert a name to a class via My proposed patch would be: - if isinstance(projection, str) or projection is None:
+ if isinstance(projection, type): # maybe: check subclass of `matplotlib.axes.Axes`
+ projection_class = projection
+ elif isinstance(projection, str) or projection is None:
projection_class = get_projection_class(projection)
elif hasattr(projection, '_as_mpl_axes'):
projection_class, extra_kwargs = projection._as_mpl_axes()
kwargs.update(**extra_kwargs)
else:
raise TypeError('projection must be a string, None or implement a '
'_as_mpl_axes method. Got %r' % projection)
` |
@eric-wieser That isn't too bad, but it is still a workaround to satisfy linters. (In my opinion, |
I honestly believe we should be perfectly happy to skip style checks in the examples if that leads to more convoluted code, see #11621 (comment) (which quite a few other core devs agree with). Let's not overthink this. |
This isn't just about the example though - it's about downstream code using style checks having to work around this too. I'd argue that requiring users to import something but then not use it directly is confusing, and violates "Explicit is better than implicit". If you view the style checkers as opinionated interpretations of what is considered "pythonic", then you could argue that if your API design requires you to make a style exception at all call sites, it might be unpythonic. I'm not saying |
I think this has enough core devs against this change, and whether our unused import is bad style or not, thats how its currently done. Closing but fee free to re-open if this PR wants to morph into setting the exception in |
The issue is resolved by #13520. |
…ction parameters.
PR Summary
PR Checklist