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

bpo-19072: Make @classmethod support chained decorators#8405

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

Conversation

berkerpeksag
Copy link
Member

@berkerpeksagberkerpeksag commentedJul 23, 2018
edited by bedevere-bot
Loading

saulshanabrook reacted with thumbs up emoji
Copy link
Member

@serhiy-storchakaserhiy-storchaka left a comment

Choose a reason for hiding this comment

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

Please provide microbenchmark results.

@@ -183,6 +183,27 @@ def test_refleaks_in___init__(self):
fake_prop.__init__('fget', 'fset', 'fdel', 'doc')
self.assertAlmostEqual(gettotalrefcount() - refs_before, 0, delta=10)

@unittest.skipIf(sys.flags.optimize >= 2,
"Docstrings are omitted with -O2 and above")

Choose a reason for hiding this comment

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

Does sys.flags.optimize really affects this test?

@rhettingerrhettinger merged commit805f8f9 intopython:masterAug 24, 2019
@berkerpeksagberkerpeksag deleted the 19072-classmethod-descriptor branchAugust 24, 2019 23:35
lisroach pushed a commit to lisroach/cpython that referenced this pull requestSep 10, 2019
DinoV pushed a commit to DinoV/cpython that referenced this pull requestJan 14, 2020
websurfer5 pushed a commit to websurfer5/cpython that referenced this pull requestJul 20, 2020
eriknw added a commit to eriknw/cpython that referenced this pull requestOct 18, 2020
bpo-19072 (python#8405) allows `classmethod` to wrap other descriptors, but this doesnot work when the wrapped descriptor mimics classmethod.  The current PR fixesthis.In Python 3.8 and before, one could create a callable descriptor such that thisworks as expected (see Lib/test/test_decorators.py for examples):```pythonclass A:    @myclassmethod    def f1(cls):        return cls@classmethod    @myclassmethod    def f2(cls):        return cls```In Python 3.8 and before, `A.f2()` return `A`. Currently in Python 3.9, itreturns `type(A)`.  This PR make `A.f2()` return `A` again.As ofpython#8405, classmethod calls `obj.__get__(type)` if `obj` has `__get__`.This allows one to chain `@classmethod` and `@property` together.  Whenusing classmethod-like descriptors, it's the second argument to `__get__`--theowner or the type--that is important, but this argument is currently missing.Since it is None, the "owner" argument is assumed to be the type of the firstargument, which, in this case, is wrong (we want `A`, not `type(A)`).This PR updates classmethod to call `obj.__get__(type, type)` if `obj` has`__get__`.
ambv added a commit to ambv/cpython that referenced this pull requestJul 15, 2021
Patch by Erik Welch.bpo-19072 (python#8405) allows `classmethod` to wrap other descriptors, but this doesnot work when the wrapped descriptor mimics classmethod.  The current PR fixesthis.In Python 3.8 and before, one could create a callable descriptor such that thisworks as expected (see Lib/test/test_decorators.py for examples):```pythonclass A:    @myclassmethod    def f1(cls):        return cls@classmethod    @myclassmethod    def f2(cls):        return cls```In Python 3.8 and before, `A.f2()` return `A`. Currently in Python 3.9, itreturns `type(A)`.  This PR make `A.f2()` return `A` again.As ofpython#8405, classmethod calls `obj.__get__(type)` if `obj` has `__get__`.This allows one to chain `@classmethod` and `@property` together.  Whenusing classmethod-like descriptors, it's the second argument to `__get__`--theowner or the type--that is important, but this argument is currently missing.Since it is None, the "owner" argument is assumed to be the type of the firstargument, which, in this case, is wrong (we want `A`, not `type(A)`).This PR updates classmethod to call `obj.__get__(type, type)` if `obj` has`__get__`.Co-authored-by: Erik Welch <erik.n.welch@gmail.com>
ambv added a commit that referenced this pull requestJul 15, 2021
…rs (#27115)Patch by Erik Welch.bpo-19072 (#8405) allows `classmethod` to wrap other descriptors, but this doesnot work when the wrapped descriptor mimics classmethod.  The current PR fixesthis.In Python 3.8 and before, one could create a callable descriptor such that thisworks as expected (see Lib/test/test_decorators.py for examples):```pythonclass A:    @myclassmethod    def f1(cls):        return cls@classmethod    @myclassmethod    def f2(cls):        return cls```In Python 3.8 and before, `A.f2()` return `A`. Currently in Python 3.9, itreturns `type(A)`.  This PR make `A.f2()` return `A` again.As of#8405, classmethod calls `obj.__get__(type)` if `obj` has `__get__`.This allows one to chain `@classmethod` and `@property` together.  Whenusing classmethod-like descriptors, it's the second argument to `__get__`--theowner or the type--that is important, but this argument is currently missing.Since it is None, the "owner" argument is assumed to be the type of the firstargument, which, in this case, is wrong (we want `A`, not `type(A)`).This PR updates classmethod to call `obj.__get__(type, type)` if `obj` has`__get__`.Co-authored-by: Erik Welch <erik.n.welch@gmail.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this pull requestJul 15, 2021
…rs (pythonGH-27115)Patch by Erik Welch.bpo-19072 (pythonGH-8405) allows `classmethod` to wrap other descriptors, but this doesnot work when the wrapped descriptor mimics classmethod.  The current PR fixesthis.In Python 3.8 and before, one could create a callable descriptor such that thisworks as expected (see Lib/test/test_decorators.py for examples):```pythonclass A:    @myclassmethod    def f1(cls):        return cls@classmethod    @myclassmethod    def f2(cls):        return cls```In Python 3.8 and before, `A.f2()` return `A`. Currently in Python 3.9, itreturns `type(A)`.  This PR make `A.f2()` return `A` again.As ofpythonGH-8405, classmethod calls `obj.__get__(type)` if `obj` has `__get__`.This allows one to chain `@classmethod` and `@property` together.  Whenusing classmethod-like descriptors, it's the second argument to `__get__`--theowner or the type--that is important, but this argument is currently missing.Since it is None, the "owner" argument is assumed to be the type of the firstargument, which, in this case, is wrong (we want `A`, not `type(A)`).This PR updates classmethod to call `obj.__get__(type, type)` if `obj` has`__get__`.Co-authored-by: Erik Welch <erik.n.welch@gmail.com>(cherry picked from commitb83861f)Co-authored-by: Łukasz Langa <lukasz@langa.pl>
ambv pushed a commit that referenced this pull requestJul 15, 2021
…rs (GH-27115) (GH-27162)Patch by Erik Welch.bpo-19072 (GH-8405) allows `classmethod` to wrap other descriptors, but this doesnot work when the wrapped descriptor mimics classmethod.  The current PR fixesthis.In Python 3.8 and before, one could create a callable descriptor such that thisworks as expected (see Lib/test/test_decorators.py for examples):```pythonclass A:    @myclassmethod    def f1(cls):        return cls@classmethod    @myclassmethod    def f2(cls):        return cls```In Python 3.8 and before, `A.f2()` return `A`. Currently in Python 3.9, itreturns `type(A)`.  This PR make `A.f2()` return `A` again.As ofGH-8405, classmethod calls `obj.__get__(type)` if `obj` has `__get__`.This allows one to chain `@classmethod` and `@property` together.  Whenusing classmethod-like descriptors, it's the second argument to `__get__`--theowner or the type--that is important, but this argument is currently missing.Since it is None, the "owner" argument is assumed to be the type of the firstargument, which, in this case, is wrong (we want `A`, not `type(A)`).This PR updates classmethod to call `obj.__get__(type, type)` if `obj` has`__get__`.Co-authored-by: Erik Welch <erik.n.welch@gmail.com>(cherry picked from commitb83861f)
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@serhiy-storchakaserhiy-storchakaserhiy-storchaka left review comments

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

5 participants
@berkerpeksag@serhiy-storchaka@rhettinger@the-knights-who-say-ni@bedevere-bot

[8]ページ先頭

©2009-2025 Movatter.jp