Shorter property deprecation.#18688
Conversation
brunobeltran
left a comment
There was a problem hiding this comment.
Is there a reason you didn't make a helper function (just a private guy) that is explicitly for properties? It looks like literally every instance you changed could have been
from .cbook import _deprecate_prop
...
prop = _deprecate_prop("3.X", lambda self: self.whatever())instead of
from . import cbook
...
prop = cbook.deprecated("3.X", property(lambda: self.whatever()))
lib/mpl_toolkits/mplot3d/axes3d.py
Outdated
| w_xaxis = cbook.deprecated("3.1", alternative="xaxis", pending=True)( | ||
| lambda self: self.xaxis) | ||
| w_yaxis = cbook.deprecated("3.1", alternative="yaxis", pending=True)( | ||
| lambda self: self.yaxis) | ||
| w_zaxis = cbook.deprecated("3.1", alternative="zaxis", pending=True)( | ||
| lambda self: self.zaxis) |
|
Lambdas are okay on a single line, but I'm not so sure I'm in favour of some of these changes to multi-line things. |
|
I don't think foo = cbook.deprecated_property("x.y", lambda self: ...)is really better (or worse) than foo = cbook.deprecated("x.y", property(lambda self: ...))I see this a bit like https://docs.python.org/3/library/abc.html#abc.abstractproperty, which was deprecated in favor of stacking I'm fine with reverting some of the multiline cases. |
| fontweights = cbook.deprecated("3.3")(property(lambda self: { | ||
| 100: cairo.FONT_WEIGHT_NORMAL, | ||
| 200: cairo.FONT_WEIGHT_NORMAL, | ||
| 300: cairo.FONT_WEIGHT_NORMAL, | ||
| 400: cairo.FONT_WEIGHT_NORMAL, | ||
| 500: cairo.FONT_WEIGHT_NORMAL, | ||
| 600: cairo.FONT_WEIGHT_BOLD, | ||
| 700: cairo.FONT_WEIGHT_BOLD, | ||
| 800: cairo.FONT_WEIGHT_BOLD, | ||
| 900: cairo.FONT_WEIGHT_BOLD, | ||
| 'ultralight': cairo.FONT_WEIGHT_NORMAL, | ||
| 'light': cairo.FONT_WEIGHT_NORMAL, | ||
| 'normal': cairo.FONT_WEIGHT_NORMAL, | ||
| 'medium': cairo.FONT_WEIGHT_NORMAL, | ||
| 'regular': cairo.FONT_WEIGHT_NORMAL, | ||
| 'semibold': cairo.FONT_WEIGHT_BOLD, | ||
| 'bold': cairo.FONT_WEIGHT_BOLD, | ||
| 'heavy': cairo.FONT_WEIGHT_BOLD, | ||
| 'ultrabold': cairo.FONT_WEIGHT_BOLD, | ||
| 'black': cairo.FONT_WEIGHT_BOLD, | ||
| })) | ||
| fontangles = cbook.deprecated("3.3")(property(lambda self: { | ||
| 'italic': cairo.FONT_SLANT_ITALIC, | ||
| 'normal': cairo.FONT_SLANT_NORMAL, | ||
| 'oblique': cairo.FONT_SLANT_OBLIQUE, | ||
| })) | ||
| mathtext_parser = cbook.deprecated("3.4")( | ||
| property(lambda self: MathTextParser('Cairo'))) |
There was a problem hiding this comment.
This is the only one that doesn't accomplish your goal IMO of making it "easier" to see the deprecated function as a block. If instead you did
| fontweights = cbook.deprecated("3.3")(property(lambda self: { | |
| 100: cairo.FONT_WEIGHT_NORMAL, | |
| 200: cairo.FONT_WEIGHT_NORMAL, | |
| 300: cairo.FONT_WEIGHT_NORMAL, | |
| 400: cairo.FONT_WEIGHT_NORMAL, | |
| 500: cairo.FONT_WEIGHT_NORMAL, | |
| 600: cairo.FONT_WEIGHT_BOLD, | |
| 700: cairo.FONT_WEIGHT_BOLD, | |
| 800: cairo.FONT_WEIGHT_BOLD, | |
| 900: cairo.FONT_WEIGHT_BOLD, | |
| 'ultralight': cairo.FONT_WEIGHT_NORMAL, | |
| 'light': cairo.FONT_WEIGHT_NORMAL, | |
| 'normal': cairo.FONT_WEIGHT_NORMAL, | |
| 'medium': cairo.FONT_WEIGHT_NORMAL, | |
| 'regular': cairo.FONT_WEIGHT_NORMAL, | |
| 'semibold': cairo.FONT_WEIGHT_BOLD, | |
| 'bold': cairo.FONT_WEIGHT_BOLD, | |
| 'heavy': cairo.FONT_WEIGHT_BOLD, | |
| 'ultrabold': cairo.FONT_WEIGHT_BOLD, | |
| 'black': cairo.FONT_WEIGHT_BOLD, | |
| })) | |
| fontangles = cbook.deprecated("3.3")(property(lambda self: { | |
| 'italic': cairo.FONT_SLANT_ITALIC, | |
| 'normal': cairo.FONT_SLANT_NORMAL, | |
| 'oblique': cairo.FONT_SLANT_OBLIQUE, | |
| })) | |
| mathtext_parser = cbook.deprecated("3.4")( | |
| property(lambda self: MathTextParser('Cairo'))) | |
| fontweights = cbook.deprecated("3.3")(property(lambda self: _fontweights)) | |
| fontangles = cbook.deprecated("3.3")(property(lambda self: _fontangles)) | |
| mathtext_parser = cbook.deprecated("3.4")( | |
| property(lambda self: MathTextParser('Cairo'))) |
and added right above the class definition something like
# deprecated font property mappings for RendererCairo
_fontweights = {
100: cairo.FONT_WEIGHT_NORMAL,
200: cairo.FONT_WEIGHT_NORMAL,
300: cairo.FONT_WEIGHT_NORMAL,
400: cairo.FONT_WEIGHT_NORMAL,
500: cairo.FONT_WEIGHT_NORMAL,
600: cairo.FONT_WEIGHT_BOLD,
700: cairo.FONT_WEIGHT_BOLD,
800: cairo.FONT_WEIGHT_BOLD,
900: cairo.FONT_WEIGHT_BOLD,
'ultralight': cairo.FONT_WEIGHT_NORMAL,
'light': cairo.FONT_WEIGHT_NORMAL,
'normal': cairo.FONT_WEIGHT_NORMAL,
'medium': cairo.FONT_WEIGHT_NORMAL,
'regular': cairo.FONT_WEIGHT_NORMAL,
'semibold': cairo.FONT_WEIGHT_BOLD,
'bold': cairo.FONT_WEIGHT_BOLD,
'heavy': cairo.FONT_WEIGHT_BOLD,
'ultrabold': cairo.FONT_WEIGHT_BOLD,
'black': cairo.FONT_WEIGHT_BOLD,
}
_fontangles = {
'italic': cairo.FONT_SLANT_ITALIC,
'normal': cairo.FONT_SLANT_NORMAL,
'oblique': cairo.FONT_SLANT_OBLIQUE,
}then I think you would accomplish your goal.
There was a problem hiding this comment.
My "feeling" is that I might have not even complained about the multiline stuff it it had also been moved to the top of the class, but leaving what looks like a class variable hiding between method definitions felt funny to me.
I agree especially that in places like texmanager this greatly reduces visual clutter.
I feel that just stashing all the deprecated properties into a single block with no blank lines in between makes it easier to ignore that block.
I'd approve if
- the "block" was moved above
__init__, where class variables are typically defined - fix the RendererCairo case to actually make this block easy to "see" as you're scrolling (see the one comment above)
I think in that case you wouldn't really have to revert any of the multi-line ones to make me happy, but in cases where you've just taken one method of a class and instead made it into a multi-line class variable definition, this might have just made this harder to understand quickly with no real benefit in terms of having things in a "block", since there's just one "thing".
|
OK, I reverted the cases of single deprecations turning into multiline blocks. |
brunobeltran
left a comment
There was a problem hiding this comment.
Not going to die on the "these should go above __init__ hill, since I can just open a separate PR to impose my opinions about this, and I will be wanting this lambda syntax for the deprecation-spree I'm about to go on.
So feel free to ignore, but I marked everywhere where they're not currently above __init__. I would say that there is one place left where you didn't put all the deprecations into a single block, which was your original purpose I think (TextBox in widgets.py).
|
Moved all of them up, except for the case where I'm just removing the |
| 'normal': cairo.FONT_SLANT_NORMAL, | ||
| 'oblique': cairo.FONT_SLANT_OBLIQUE, | ||
| } | ||
| fontweights = cbook.deprecated("3.3")(property(lambda self: _fontweights)) |
There was a problem hiding this comment.
| fontweights = cbook.deprecated("3.3")(property(lambda self: _fontweights)) | |
| fontweights = cbook.deprecated("3.3")(property(lambda self: dict(_fontweights))) |
| 'oblique': cairo.FONT_SLANT_OBLIQUE, | ||
| } | ||
| fontweights = cbook.deprecated("3.3")(property(lambda self: _fontweights)) | ||
| fontangles = cbook.deprecated("3.3")(property(lambda self: _fontangles)) |
There was a problem hiding this comment.
| fontangles = cbook.deprecated("3.3")(property(lambda self: _fontangles)) | |
| fontangles = cbook.deprecated("3.3")(property(lambda self: dict(_fontangles))) |
This and the line above used to return a fresh dict that the user could modify, this makes sure we do not start leaking mutable global state out.
This lets us write deprecated properties with single-line lambdas, which is quite a bit more compact (as shown by the line diff).
| @cbook.deprecated("3.3") | ||
| @property | ||
| def mathtext_parser(self): | ||
| return MathTextParser("PS") |
There was a problem hiding this comment.
This used to be the wrong 'since' version, I guess?
This lets us write deprecated properties with single-line lambdas, which
is quite a bit more compact (as shown by the line diff).
PR Summary
PR Checklist
pytestpasses).flake8on changed files to check).flake8-docstringsandpydocstyle<4and runflake8 --docstring-convention=all).doc/users/next_whats_new/(follow instructions in README.rst there).doc/api/next_api_changes/(follow instructions in README.rst there).