Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5a9ea37

Browse files
committed
Deprecate case-insensitive capstyles and joinstyles.
Collections have never accepted case-sensitive capstyles/joinstyles (their setter don't do `s.lower()` first) but AFAIK no one has complained about it, which suggests their use is rare. There isn't much of a reason in supporting them, case-insensitive APIs are not-so pythonic, and unsupporting them makes code map more easily to cbook._check_in_list.
1 parent f11e538 commit 5a9ea37

File tree

4 files changed

+47
-19
lines changed

4 files changed

+47
-19
lines changed

doc/api/next_api_changes/deprecations.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,8 @@ PDF and PS character tracking internals
4747
The ``used_characters`` attribute and ``track_characters`` and
4848
``merge_used_characters`` methods of `.RendererPdf`, `.PdfFile`, and
4949
`.RendererPS` are deprecated.
50+
51+
Case-insensitive capstyles and joinstyles
52+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
53+
Please pass capstyles ("miter", "round", "bevel") and joinstyles ("butt",
54+
"round", "projecting") as lowercase.

lib/matplotlib/lines.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import numpy as np
1111

12+
import matplotlib as mpl
1213
from . import artist, cbook, colors as mcolors, docstring, rcParams
1314
from .artist import Artist, allow_rasterization
1415
from .cbook import (
@@ -1366,7 +1367,7 @@ def set_dash_joinstyle(self, s):
13661367
s : {'miter', 'round', 'bevel'}
13671368
For examples see :doc:`/gallery/lines_bars_and_markers/joinstyle`.
13681369
"""
1369-
s = s.lower()
1370+
s = mpl.rcsetup._deprecate_case_insensitive_join_cap(s)
13701371
cbook._check_in_list(self.validJoin, s=s)
13711372
if self._dashjoinstyle != s:
13721373
self.stale = True
@@ -1381,7 +1382,7 @@ def set_solid_joinstyle(self, s):
13811382
s : {'miter', 'round', 'bevel'}
13821383
For examples see :doc:`/gallery/lines_bars_and_markers/joinstyle`.
13831384
"""
1384-
s = s.lower()
1385+
s = mpl.rcsetup._deprecate_case_insensitive_join_cap(s)
13851386
cbook._check_in_list(self.validJoin, s=s)
13861387
if self._solidjoinstyle != s:
13871388
self.stale = True
@@ -1412,7 +1413,7 @@ def set_dash_capstyle(self, s):
14121413
s : {'butt', 'round', 'projecting'}
14131414
For examples see :doc:`/gallery/lines_bars_and_markers/joinstyle`.
14141415
"""
1415-
s = s.lower()
1416+
s = mpl.rcsetup._deprecate_case_insensitive_join_cap(s)
14161417
cbook._check_in_list(self.validCap, s=s)
14171418
if self._dashcapstyle != s:
14181419
self.stale = True
@@ -1427,7 +1428,7 @@ def set_solid_capstyle(self, s):
14271428
s : {'butt', 'round', 'projecting'}
14281429
For examples see :doc:`/gallery/lines_bars_and_markers/joinstyle`.
14291430
"""
1430-
s = s.lower()
1431+
s = mpl.rcsetup._deprecate_case_insensitive_join_cap(s)
14311432
cbook._check_in_list(self.validCap, s=s)
14321433
if self._solidcapstyle != s:
14331434
self.stale = True

lib/matplotlib/patches.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ class Patch(artist.Artist):
3232
are *None*, they default to their rc params setting.
3333
"""
3434
zorder = 1
35-
validCap = ('butt', 'round', 'projecting')
36-
validJoin = ('miter', 'round', 'bevel')
35+
validCap = mlines.Line2D.validCap
36+
validJoin = mlines.Line2D.validJoin
3737

3838
# Whether to draw an edge by default. Set on a
3939
# subclass-by-subclass basis.
@@ -463,7 +463,7 @@ def set_capstyle(self, s):
463463
----------
464464
s : {'butt', 'round', 'projecting'}
465465
"""
466-
s = s.lower()
466+
s = mpl.rcsetup._deprecate_case_insensitive_join_cap(s)
467467
cbook._check_in_list(self.validCap, capstyle=s)
468468
self._capstyle = s
469469
self.stale = True
@@ -479,7 +479,7 @@ def set_joinstyle(self, s):
479479
----------
480480
s : {'miter', 'round', 'bevel'}
481481
"""
482-
s = s.lower()
482+
s = mpl.rcsetup._deprecate_case_insensitive_join_cap(s)
483483
cbook._check_in_list(self.validJoin, joinstyle=s)
484484
self._joinstyle = s
485485
self.stale = True

lib/matplotlib/rcsetup.py

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -580,19 +580,41 @@ def _is_iterable_not_string_like(x):
580580
raise ValueError(f"linestyle {ls!r} is not a valid on-off ink sequence.")
581581

582582

583-
validate_joinstyle = ValidateInStrings('joinstyle',
584-
['miter', 'round', 'bevel'],
585-
ignorecase=True)
586-
validate_joinstylelist = _listify_validator(validate_joinstyle)
583+
def _deprecate_case_insensitive_join_cap(s):
584+
s_low = s.lower()
585+
if s != s_low:
586+
if s_low in ['miter', 'round', 'bevel']:
587+
cbook.warn_deprecated(
588+
"3.3", message="Case-insensitive capstyles are deprecated "
589+
"since %(since)s and support for them will be removed "
590+
"%(removal)s; please pass them in lowercase.")
591+
elif s_low in ['butt', 'round', 'projecting']:
592+
cbook.warn_deprecated(
593+
"3.3", message="Case-insensitive joinstyles are deprecated "
594+
"since %(since)s and support for them will be removed "
595+
"%(removal)s; please pass them in lowercase.")
596+
# Else, error out at the check_in_list stage.
597+
return s_low
598+
599+
600+
def validate_joinstyle(s):
601+
s = _deprecate_case_insensitive_join_cap(s)
602+
cbook._check_in_list(['miter', 'round', 'bevel'], joinstyle=s)
603+
return s
587604

588-
validate_capstyle = ValidateInStrings('capstyle',
589-
['butt', 'round', 'projecting'],
590-
ignorecase=True)
591-
validate_capstylelist = _listify_validator(validate_capstyle)
592605

593-
validate_fillstyle = ValidateInStrings('markers.fillstyle',
594-
['full', 'left', 'right', 'bottom',
595-
'top', 'none'])
606+
def validate_capstyle(s):
607+
s = _deprecate_case_insensitive_join_cap(s)
608+
cbook._check_in_list(['butt', 'round', 'projecting'], capstyle=s)
609+
return s
610+
611+
612+
validate_fillstyle = ValidateInStrings(
613+
'markers.fillstyle', ['full', 'left', 'right', 'bottom', 'top', 'none'])
614+
615+
616+
validate_joinstylelist = _listify_validator(validate_joinstyle)
617+
validate_capstylelist = _listify_validator(validate_capstyle)
596618
validate_fillstylelist = _listify_validator(validate_fillstyle)
597619

598620

0 commit comments

Comments
 (0)