Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Shorter property deprecation.#18688
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
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 .cbookimport_deprecate_prop...prop=_deprecate_prop("3.X",lambdaself:self.whatever())
instead of
from .importcbook...prop=cbook.deprecated("3.X",property(lambda:self.whatever()))
Uh oh!
There was an error while loading.Please reload this page.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Forgot theproperty
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
yup
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. |
anntzer commentedOct 8, 2020 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
I don't think foo=cbook.deprecated_property("x.y",lambdaself: ...) is really better (or worse) than foo=cbook.deprecated("x.y",property(lambdaself: ...)) I see this a bit likehttps://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'))) |
brunobeltranOct 8, 2020 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
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(lambdaself: { | |
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(lambdaself: { | |
'italic':cairo.FONT_SLANT_ITALIC, | |
'normal':cairo.FONT_SLANT_NORMAL, | |
'oblique':cairo.FONT_SLANT_OBLIQUE, | |
})) | |
mathtext_parser=cbook.deprecated("3.4")( | |
property(lambdaself:MathTextParser('Cairo'))) | |
fontweights=cbook.deprecated("3.3")(property(lambdaself:_fontweights)) | |
fontangles=cbook.deprecated("3.3")(property(lambdaself:_fontangles)) | |
mathtext_parser=cbook.deprecated("3.4")( | |
property(lambdaself: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.
brunobeltran left a comment• edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
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 liketexmanager
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'treally have to revert any of the multi-line ones to makeme happy, but in cases where you've just takenone 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 ofsingle deprecations turning into multiline blocks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
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).
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Moved all of them up, except for the case where I'mjust 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
fontweights=cbook.deprecated("3.3")(property(lambdaself:_fontweights)) | |
fontweights=cbook.deprecated("3.3")(property(lambdaself:dict(_fontweights))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
ditto
'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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
fontangles=cbook.deprecated("3.3")(property(lambdaself:_fontangles)) | |
fontangles=cbook.deprecated("3.3")(property(lambdaself: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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
done
This lets us write deprecated properties with single-line lambdas, whichis 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
This used to be the wrong 'since' version, I guess?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
yes (#18002)
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
pytest
passes).flake8
on changed files to check).flake8-docstrings
andpydocstyle<4
and 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).