bpo-44807: Allow Protocol classes to define init by adriangb · Pull Request #31628 · python/cpython (original) (raw)

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 our terms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation9 Commits7 Checks0 Files changed

Conversation

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

[ Show hidden characters]({{ revealButtonHref }})

adriangb

@adriangb

@adriangb adriangb marked this pull request as ready for review

March 1, 2022 06:23

JelleZijlstra

# the protocol itself cannot be instantiated
with self.assertRaises(TypeError):
P()

Choose a reason for hiding this comment

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

But presumably P(1) will work?

Choose a reason for hiding this comment

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

Great catch. This is a bad assertion with an even worse comment: this TypeError is occurring because it's missing an argument, not because of the no-instantiation check. I'm inclined to just remove this assertRaises. What do you think?

Choose a reason for hiding this comment

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

Agree that the current test doesn't make much sense. It would be useful though to add a test that asserts that P.__init__ doesn't get clobbered. For example, you could call P.__init__(some_object, 1) directly.

(Also, unrelatedly, this change will need a NEWS entry.)

Choose a reason for hiding this comment

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

Thank you for the feedback.

I split up the test into 2:

  1. Verify that __init__ is no longer clobbered (as per your suggestion)
  2. Check that concrete subclasses can inherit and use init from a protocol class

@blurb-it

@adriangb

JelleZijlstra

@adriangb @JelleZijlstra

Co-authored-by: Jelle Zijlstra jelle.zijlstra@gmail.com

@adriangb @JelleZijlstra

Co-authored-by: Jelle Zijlstra jelle.zijlstra@gmail.com

@adriangb @JelleZijlstra

Co-authored-by: Jelle Zijlstra jelle.zijlstra@gmail.com

JelleZijlstra

@JelleZijlstra

JelleZijlstra

Choose a reason for hiding this comment

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

Gobot1234 added a commit to Gobot1234/typing_extensions that referenced this pull request

Feb 20, 2023

@Gobot1234

kraj pushed a commit to YoeDistro/poky that referenced this pull request

Jun 1, 2023

@wangmingyu84 @alexandrebelloni

Changelog:

(From OE-Core rev: 2b1d07c7deb4f0247765bc737fb11a1747143edf)

Signed-off-by: Wang Mingyu wangmy@fujitsu.com Signed-off-by: Alexandre Belloni alexandre.belloni@bootlin.com

rpurdie pushed a commit to yoctoproject/poky that referenced this pull request

Jun 2, 2023

@wangmingyu84 @rpurdie

Changelog:

(From OE-Core rev: a37154b9166323d05cca970ebb37bee0d5250893)

Signed-off-by: Wang Mingyu wangmy@fujitsu.com Signed-off-by: Alexandre Belloni alexandre.belloni@bootlin.com Signed-off-by: Richard Purdie richard.purdie@linuxfoundation.org

halstead pushed a commit to openembedded/openembedded-core that referenced this pull request

Jun 2, 2023

@wangmingyu84 @rpurdie

Changelog:

Signed-off-by: Wang Mingyu wangmy@fujitsu.com Signed-off-by: Alexandre Belloni alexandre.belloni@bootlin.com

renovate bot referenced this pull request in allenporter/flux-local

Jun 3, 2023

@renovate

Mend
Renovate](https://renovatebot.com)

This PR contains the following updates:

Package Change Age Adoption Passing Confidence
typing-extensions
(changelog)
==4.5.0 -> ==4.6.3
age](https://docs.renovatebot.com/merge-confidence/)
adoption](https://docs.renovatebot.com/merge-confidence/)
passing](https://docs.renovatebot.com/merge-confidence/)
confidence](https://docs.renovatebot.com/merge-confidence/)

Release Notes

python/typing_extensions

v4.6.3

Compare Source

v4.6.2

Compare Source

v4.6.1

Compare Source

v4.6.0

Compare Source

https://github.com/python/cpython/pull/232943294 https://github.com/python/cpython/pull/23383ll/23383. Both CPython PRs were originally by Yurii Karabas, and both were backported to Python >=3.9.1, but no earlier. Patch by Alex Waygood.

A side effect of one of the changes is that equality comparisons of Literal objects will now raise a TypeError if one of the Literal objects being compared has a mutable parameter. (Using mutable parameters with Literal is not supported by PEP 586 or by any major static type checkers.)

https://github.com/python/cpython/pull/293349334. (The CPython bugfix was backported to CPython 3.10.1 and 3.9.8, but no earlier.)

A side effect of one of the performance improvements is that the members of a runtime-checkable protocol are now considered “frozen” at runtime as soon as the class has been created. Monkey-patching attributes onto a runtime-checkable protocol will still work, but will have no impact on isinstance() checks comparing objects to the protocol. See "What's New in Python 3.12" for more details.

types.get_original_bases, introduced in Python 3.12 (CPythonhttps://github.com/python/cpython/pull/101827l/101827, originally by James Hilton-Balfe). Patch by Alex Waygood.

This function should always produce correct results when called on classes constructed using features from typing_extensions. However, it may produce incorrect results when called on some NamedTuple or TypedDict classes that use typing.{NamedTuple,TypedDict} on Python <=3.11.

https://github.com/python/cpython/pull/1040484048). Patch by Alex Waygood.


Configuration

📅 Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 Automerge: Enabled.

Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 Ignore: Close this PR and you won't be reminded about this update again.



This PR has been generated by Mend Renovate. View repository job log here.

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

daregit pushed a commit to daregit/yocto-combined that referenced this pull request

May 22, 2024

@wangmingyu84 @rpurdie

Changelog:

(From OE-Core rev: a37154b9166323d05cca970ebb37bee0d5250893)

Signed-off-by: Wang Mingyu wangmy@fujitsu.com Signed-off-by: Alexandre Belloni alexandre.belloni@bootlin.com Signed-off-by: Richard Purdie richard.purdie@linuxfoundation.org