Skip to content

Fix validation of linestyle in rcparams and cycler. #15827

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

Merged
merged 1 commit into from
Dec 8, 2019

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Dec 3, 2019

Correcly use _validate_linestyle instead of validate_stringlist in the
cycler linestyle validator. For compat, support both the (on, off, on,
off, ...) and (offset, (on, off, on, off, ...)) forms. Don't support
passing on, off, etc. as individual separate strings anymore as that's
not a realistic use case (unlike passing the whole thing as a single
string, which is supported for parsing the rc file).

Closes #15825 (the corresponding test is that (0, [1, 2]) no longer fails but is instead parsed as (0, [1, 2])).
Makes https://github.com/matplotlib/matplotlib/pull/8040/files#diff-2423339af6767c3b30e1882f7c8d8f54R30 actually work (it didn't before).

Note that _validate_stringlist needed to be moved up in rcsetup.py to come before the _prop_validators dict.

Edit: Also closes #9792 and supersedes #9797, from which some test cases were taken.

PR Summary

PR Checklist

  • Has Pytest style unit tests
  • Code is Flake 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

@anntzer anntzer force-pushed the linestyle-validation branch from 2b5b24e to 664ab35 Compare December 3, 2019 23:21
@tacaswell tacaswell added this to the v3.3.0 milestone Dec 5, 2019
except ValueError:
pass
try:
ls = ast.literal_eval(ls)
Copy link
Member

Choose a reason for hiding this comment

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

Is this only there to support reading rc_files? If so, I would mention this in a comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's literally the case for all functions in rcsetup.py...

Copy link
Member

@timhoffm timhoffm Dec 8, 2019

Choose a reason for hiding this comment

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

But most of them work implicitly because the don't parse nested structures. Then str -> other type is trivial.

Actually, I'd be in favor of making rcfiles YAML compliant. They mostly are already. We could delegate all the string parsing to the YAML parser. Then, the validators would only operate on the actual python types (not on their string representation). This would also be beneficial for using validators when setting rcParams directly in the code. That's for another time/discusion, but the comment would help to remove the string parsing from the validator later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a comment.

I am strongly opposed to using yaml here; it's the wrong tool for the task: it's not expressive enough to describe things that are actually problematic in the current rc syntax (axes.prop_cycler, path.effects), while bringing in a lot of complexity (a typical one being the many, many different kind of strings that exist) that is unwarranted.

Copy link
Member

Choose a reason for hiding this comment

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

axes.prop_cycle could well be described by a dict

axes.prop_cycle:
    color: ['1f77b4', 'ff7f0e', '2ca02c']
    linestyle: ['-', '--', ':']

But no need to go into that discussion here.

Correcly use _validate_linestyle instead of validate_stringlist in the
cycler linestyle validator.  For compat, support both the (on, off, on,
off, ...) and (offset, (on, off, on, off, ...)) forms.  Don't support
passing on, off, etc. as *individual* separate strings anymore as that's
not a realistic use case (unlike passing the whole thing as a single
string, which is supported for parsing the rc file).
@anntzer anntzer force-pushed the linestyle-validation branch from 664ab35 to 4899580 Compare December 8, 2019 14:24
@timhoffm
Copy link
Member

timhoffm commented Dec 8, 2019

Anybody can merge after CI pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants