Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Merged
QuLogic merged 1 commit intomatplotlib:masterfromanntzer:depprop
Oct 17, 2020
Merged

Conversation

anntzer
Copy link
Contributor

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

  • Has pytest style unit tests (andpytest passes).
  • IsFlake 8 compliant (runflake8 on changed files to check).
  • New features are documented, with examples if plot related.
  • Documentation is sphinx and numpydoc compliant (the docs shouldbuild without error).
  • Conforms to Matplotlib style conventions (installflake8-docstrings andpydocstyle<4 and runflake8 --docstring-convention=all).
  • New features have an entry indoc/users/next_whats_new/ (follow instructions in README.rst there).
  • API changes documented indoc/api/next_api_changes/ (follow instructions in README.rst there).

Copy link
Contributor

@brunobeltranbrunobeltran left a 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()))

Comment on lines 187 to 192
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)
Copy link
Contributor

Choose a reason for hiding this comment

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

Forgot theproperty.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

yup

@QuLogic
Copy link
Member

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.

story645 reacted with thumbs up emoji

@anntzer
Copy link
ContributorAuthor

anntzer commentedOct 8, 2020
edited
Loading

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 stackingabstractmethod on top ofproperty.

I'm fine with reverting some of the multiline cases.

Comment on lines 95 to 127
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')))
Copy link
Contributor

@brunobeltranbrunobeltranOct 8, 2020
edited
Loading

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

Suggested change
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.

Copy link
Contributor

@brunobeltranbrunobeltran left a comment
edited
Loading

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

  1. the "block" was moved above__init__, where class variables are typically defined
  2. 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".

@anntzer
Copy link
ContributorAuthor

OK, I reverted the cases ofsingle deprecations turning into multiline blocks.

Copy link
Contributor

@brunobeltranbrunobeltran left a 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).

@anntzer
Copy link
ContributorAuthor

Moved all of them up, except for the case where I'mjust removing thename parameter inwidgets.py.

'normal': cairo.FONT_SLANT_NORMAL,
'oblique': cairo.FONT_SLANT_OBLIQUE,
}
fontweights = cbook.deprecated("3.3")(property(lambda self: _fontweights))
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
fontweights=cbook.deprecated("3.3")(property(lambdaself:_fontweights))
fontweights=cbook.deprecated("3.3")(property(lambdaself:dict(_fontweights)))

Copy link
ContributorAuthor

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))
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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.

Copy link
ContributorAuthor

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).
Comment on lines -252 to -255
@cbook.deprecated("3.3")
@property
def mathtext_parser(self):
return MathTextParser("PS")
Copy link
Member

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?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

yes (#18002)

@QuLogicQuLogic merged commitcf83ec4 intomatplotlib:masterOct 17, 2020
@QuLogicQuLogic added this to thev3.4.0 milestoneOct 17, 2020
@anntzeranntzer deleted the depprop branchOctober 17, 2020 08:44
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@tacaswelltacaswelltacaswell left review comments

@brunobeltranbrunobeltranbrunobeltran approved these changes

@QuLogicQuLogicQuLogic approved these changes

Assignees
No one assigned
Projects
None yet
Milestone
v3.4.0
Development

Successfully merging this pull request may close these issues.

4 participants
@anntzer@QuLogic@tacaswell@brunobeltran

[8]ページ先頭

©2009-2025 Movatter.jp