FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-98963: Restore the ability to have a dict-less property. by gpshead · Pull Request #105262 · python/cpython · GitHub

/ cpython Public

gh-98963: Restore the ability to have a dict-less property. - #105262

Merged
JelleZijlstra merged 7 commits into
python:mainfrom
gpshead:property-nodict-docstr-error
Jun 5, 2023
Merged

gh-98963: Restore the ability to have a dict-less property.#105262
JelleZijlstra merged 7 commits into
python:mainfrom
gpshead:property-nodict-docstr-error

Conversation

gpshead commented Jun 3, 2023
edited
Loading

Copy link
Copy Markdown
Member

Ignore doc string assignment failures in property as has been the behavior of all past Python releases.

Preserves the one situation in which the AttributeError has always been raised for this property subclass situation:
If the docstring would be applied from a getter function it raises rather than remaining silent. (see the existing test and code comments)

This undoes a behavior regression present in 3.12beta1 that was causing existing widely used library code (Google protobuf) to fail.

Ignore doc string assignment failures in `property` as has been the
behavior of all past Python releases.

One behavior change: The longstanding tested behavior of raising an
`AttributeError` when using a slotted no-dict property subclass as a
decorator on a getter sporting a docstring is now consistent with the
subclassing behavior and does not produce an error.

This comment was marked as outdated.

gpshead marked this pull request as ready for review June 3, 2023 00:48
gpshead added the needs backport to 3.12 only security fixes label Jun 3, 2023
gpshead requested a review from Yhg1s June 3, 2023 00:53
gpshead enabled auto-merge (squash) June 4, 2023 21:14

JelleZijlstra left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This behavior is weird but it's consistent with how 3.11 works, so let's merge it. (Apart from what I think is an extraneous DECREF.)

Comment thread Objects/descrobject.c Outdated

gpshead commented Jun 5, 2023

Copy link
Copy Markdown
Member Author

This behavior is weird but it's consistent with how 3.11 works, so let's merge it.

Yeah... I can't say this is the overall set of behavior anyone would ever choose. I'm mostly aiming for minimum behavior change vs older Pythons so if we ever want to bother with changing this semi-esoteric edge case we can do it in a planned API change fashion.

adding that extra code to retain the AttributeError only when the docstring comes from getter.__doc__ feels weird, but that behavior might honestly be what we want in all cases in the long run so removing it as my initial version of this PR did felt unwise as it could lead to people unintentionally writing code that doesn't work across multiple versions if we ever choose to do that.

gpshead enabled auto-merge (squash) June 5, 2023 03:01
JelleZijlstra disabled auto-merge June 5, 2023 03:05
JelleZijlstra enabled auto-merge (squash) June 5, 2023 03:15
JelleZijlstra merged commit 418befd into python:main Jun 5, 2023

Copy link
Copy Markdown
Contributor

Thanks @gpshead for the PR, and @JelleZijlstra for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12.
🐍🍒⛏🤖

Copy link
Copy Markdown

GH-105297 is a backport of this pull request to the 3.12 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jun 5, 2023
…thonGH-105262)

Ignore doc string assignment failures in `property` as has been the
behavior of all past Python releases.
(cherry picked from commit 418befd)

Co-authored-by: Gregory P. Smith <greg@krypto.org>
bedevere-bot removed the needs backport to 3.12 only security fixes label Jun 5, 2023

gpshead commented Jun 5, 2023
edited
Loading

Copy link
Copy Markdown
Member Author

I wish github would've preserved the much longer commit message I authored for later when auto merge was disabled. :(

gpshead deleted the property-nodict-docstr-error branch June 5, 2023 03:24
gpshead added a commit that referenced this pull request Jun 5, 2023
…H-105262) (#105297)

gh-98963: Restore the ability to have a dict-less property. (GH-105262)

Ignore doc string assignment failures in `property` as has been the
behavior of all past Python releases.  (the docstring is discarded)
(cherry picked from commit 418befd)

This fixes a behavior regression in 3.12beta1 where an AttributeError was being raised in a situation it has never been in the past. It keeps the existing unusual single situation where AttributeError does get raised.

Existing widely deployed projects depend on this not raising an exception.

Co-authored-by: Gregory P. Smith <greg@krypto.org>

Copy link
Copy Markdown
Member

I wish github would've preserved the much longer commit message I authored for later when auto merge was disabled. :(

Sorry for that!

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants


Back | FazBrowse Home | New Git URL