Skip to content
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 and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-42345: Fix three issues with typing.Literal parameters #23294

Merged
merged 8 commits into from
Nov 17, 2020

Conversation

uriyyo
Copy link
Member

@uriyyo uriyyo commented Nov 15, 2020

Literal equality no longer depends on the order of arguments.

Fix issue related to typing.Literal caching by adding typed parameter to typing._tp_cache function.

Add deduplication of typing.Literal arguments.

https://bugs.python.org/issue42345

Automerge-Triggered-By: GH:gvanrossum

Copy link
Member

@Fidget-Spinner Fidget-Spinner left a comment

Choose a reason for hiding this comment

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

Hello, thank you for your PR to cpython! This looks very good to me, just one thing about de-duplicating literals pointed out in the review below.

Lib/typing.py Outdated Show resolved Hide resolved
Copy link
Member

@Fidget-Spinner Fidget-Spinner left a comment

Choose a reason for hiding this comment

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

I still think that Literal should de-duplicate its __args__ similar to Union, although I now see the set approach won't work. Maybe you can call set on the _value_and_type_iter function, then extract out the parameters again, something like:

def Literal:
    ...
    parameters = [p for p, _ in set(_value_and_type_iter(parameters))]
    return _LiteralGenericAlias(self, parameters)

This probably needs more discussion, and Guido/Ivan's decision on what the expected behavior should be. Maybe we can ask on the bpo issue.

Lib/test/test_typing.py Outdated Show resolved Hide resolved
@uriyyo
Copy link
Member Author

uriyyo commented Nov 15, 2020

@Fidget-Spinner There is a problem with Literal caching.

Code like this will fail because of type caching:

>>> Literal[0] == Literal[False]
False

Code below will show the root cause of this problem:

>>> (Literal[0], Literal[False])
(Litera[0], Literal[0])

As a solution, we can disable caching for a Literal.

What do you think about that?

@Fidget-Spinner
Copy link
Member

Fidget-Spinner commented Nov 15, 2020

Code like this will fail because of type caching:

One possible workaround for that is to pass typed=True for lru_cache in tp_cache, then it will differentiate 0 and False.

The only problem is I realized that set will still fail for passing in dict Literal.

A possible workaround is to just loop through them and check the other args one by one (not particularly efficient but I don't expect Literals to be too long, and with cache it should offset some of it), something like what _remove_dups_flatten for Union does, but instead you can't use set due to non-hashable args. Something like:

# more code here to keep track and store the unique elements
...
for index, i_elem in enumerate(parameters):
    is_duplicate = False
    for j_elem in parameters[index:]:
        if i_elem == j_elem:
            is_duplicate = True
            break
    ...
    # more code for logic to handle the unique elements

I think before we progress further, we should wait for a core dev to respond on the bpo. They might think just having comparisons work is sufficient, and that de-duplicating args isn't needed. So let's save our effort for now 😉 .

Edit:
I just remembered that _tp_cache will just default to non-cache behavior for dict literals, so it's fine to just leave it mostly untouched.

@uriyyo
Copy link
Member Author

uriyyo commented Nov 15, 2020

@Fidget-Spinner I forget about lru_cache typed parameter, thanks for the reminder

I totally agree with you, let wait for a decision from Guido and Ivan regarding Literal args de-duplicating.

As for me, we can skip args de-duplication because Literal equals method will convert everything to set so duplicates won't be a problem.

@gvanrossum
Copy link
Member

Please change the title and news text. We don’t use the style that describes the new state, we describe the action of the PR as a change to the behavior. For examples, just look at the commit log.

@uriyyo uriyyo changed the title bpo-42345: Literal equality no longer depends on order of arguments bpo-42345: Fix typing.Literal equals method to ignore the order of arguments Nov 15, 2020
@uriyyo
Copy link
Member Author

uriyyo commented Nov 15, 2020

I have updated the title and news.

Sorry for that, I didn't notice this convention. My bad.

Copy link
Member

@gvanrossum gvanrossum left a comment

Choose a reason for hiding this comment

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

LG, except for one nit.

You might mention in the description (not the title) and the news file that you also fixed an issue where incorrectly Literal[0] == Literal[False] -- good catch, that!

Lib/typing.py Show resolved Hide resolved
@uriyyo
Copy link
Member Author

uriyyo commented Nov 16, 2020

@gvanrossum I have seen your message regarding Literal args deduplication, so I have implemented it in the scope of this PR.

Copy link
Member

@Fidget-Spinner Fidget-Spinner left a comment

Choose a reason for hiding this comment

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

Getting very close :). Thank you for your patience.

Lib/typing.py Show resolved Hide resolved
Lib/typing.py Show resolved Hide resolved
Lib/typing.py Show resolved Hide resolved
Copy link
Member

@Fidget-Spinner Fidget-Spinner left a comment

Choose a reason for hiding this comment

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

LGTM, and sorry for the weird tangents I went off on in some places!

@uriyyo
Copy link
Member Author

uriyyo commented Nov 16, 2020

@Fidget-Spinner thanks for the review and all comments 🙂

What will be the next step regarding this PR?

@Fidget-Spinner
Copy link
Member

Fidget-Spinner commented Nov 16, 2020

@Fidget-Spinner thanks for the review and all comments 🙂

What will be the next step regarding this PR?

@uriyyo A core dev like Guido/Ivan will take a look, once they're satisfied and approve it, it will be merged into 3.10. And probably backported to 3.9 and 3.8 too (done automatically via bots). This may take some time depending on how busy the core devs are.

I'm looking forward to see your first commit to cpython :).

@gvanrossum
Copy link
Member

I will look at it some time this week.

@Dominik1123
Copy link
Contributor

Should the docs of typing.get_args be updated to mention Literal as well (similar to #23254)?

@bedevere-bot bedevere-bot removed the needs backport to 3.9 only security fixes label Nov 17, 2020
@uriyyo
Copy link
Member Author

uriyyo commented Nov 17, 2020

@gvanrossum Looks like I did it🙂

miss-islington pushed a commit that referenced this pull request Nov 17, 2020
…23294) (GH-23335)

Literal equality no longer depends on the order of arguments.

Fix issue related to `typing.Literal` caching by adding `typed` parameter to `typing._tp_cache` function.

Add deduplication of `typing.Literal` arguments.

(cherry picked from commit f03d318)

Co-authored-by: Yurii Karabas <[email protected]>
@Dominik1123
Copy link
Contributor

Should the docs of typing.get_args be updated to mention Literal as well (similar to #23254)?

Sure, but I would make a minimal change, e.g. changing "Union" in that paragraph to "Union or Literal".

@uriyyo What about updating the docs of typing.get_args?

@Fidget-Spinner
Copy link
Member

Fidget-Spinner commented Nov 18, 2020

Should the docs of typing.get_args be updated to mention Literal as well (similar to #23254)?

Sure, but I would make a minimal change, e.g. changing "Union" in that paragraph to "Union or Literal".

@uriyyo What about updating the docs of typing.get_args?

@Dominik1123, not sure if this is a bug, but hash() of Literal is dependent on args order in the current code, so the type caching problem won't happen. Currently, it's still only Union affected.

>>> hash(Literal[1, 2, 3])
3136223724409791019
>>> hash(Literal[3, 2, 1])
4438910888190981000

@uriyyo
Copy link
Member Author

uriyyo commented Nov 18, 2020

@Fidget-Spinner Looks like we should not update docs because Literal can't be parametrized with generics so this problem will not exist for Literal. Please correct me if I miss smth.

@gvanrossum
Copy link
Member

But Literal can occur inside other types, e.g. Tuple[str, str, Literal[0, 1, 2]].

@Fidget-Spinner
Copy link
Member

Fidget-Spinner commented Nov 18, 2020

@uriyyo yeah, sorry if I wasn't clear in my original statement - I was in support of not updating the docs. Although my reasoning is slightly different. It's not about generics, the behavior Dominik mentioned happens when Union's nested in anything. The real reason why we don't need a docs update is because the __hash__ of Literal in your patch is order-dependent.

Edit:
Eg:

# Union with __args__ not preserving order when nested due to type caching.
>>> Tuple[Union[int, str]].__args__
(typing.Union[int, str],)
>>> Tuple[Union[str, int]].__args__
(typing.Union[int, str],)

# Literal doesn't have that issue
>>> Tuple[Literal[1, 2]].__args__
(typing.Literal[1, 2],)
>>> Tuple[Literal[2, 1]].__args__
(typing.Literal[2, 1],)

@uriyyo
Copy link
Member Author

uriyyo commented Nov 18, 2020

@Fidget-Spinner Thanks for the explanation it's clear to me now.

@Fidget-Spinner
Copy link
Member

Fidget-Spinner commented Nov 18, 2020

@uriyyo Awesome! I'm glad I was able to help :).

Oops, forgot to say this: Congrats to your first commit to CPython!

@Dominik1123
Copy link
Contributor

Should the docs of typing.get_args be updated to mention Literal as well (similar to #23254)?

Sure, but I would make a minimal change, e.g. changing "Union" in that paragraph to "Union or Literal".

@uriyyo What about updating the docs of typing.get_args?

@Dominik1123, not sure if this is a bug, but hash() of Literal is dependent on args order in the current code, so the type caching problem won't happen. Currently, it's still only Union affected.

>>> hash(Literal[1, 2, 3])
3136223724409791019
>>> hash(Literal[3, 2, 1])
4438910888190981000

@Fidget-Spinner @uriyyo I see, I didn't notice before. But isn't this very unusual in terms of behavior? So we can have two objects that compare equal but their hashes are different. AFAIK nowhere else in Python this is the case. The closest that comes to it in terms "being equal, but not having the same hash" is set and frozenset but in that case at least set will raise. Now for Literal it's yet another level, since the hashes are actually computed, and it's even the same type.

To quote the Python data model on __hash__:

The only required property is that objects which compare equal have the same hash value;

So according to that it's a bug and the hash should not be order dependent.

@uriyyo
Copy link
Member Author

uriyyo commented Nov 18, 2020

@Dominik1123 Agree with you, looks like it's a bug related to Literal hash implementation, basically, we should change implementation from:

    def __hash__(self):
        return hash(tuple(_value_and_type_iter(self.__args__)))

to:

    def __hash__(self):
        return hash(frozentset(_value_and_type_iter(self.__args__)))

@Fidget-Spinner should we create issue regarding this bug?

@Dominik1123
Copy link
Contributor

@Dominik1123 Agree with you, looks like it's a bug related to Literal hash implementation, basically, we should change implementation from:

    def __hash__(self):
        return hash(tuple(_value_and_type_iter(self.__args__)))

to:

    def __hash__(self):
        return hash(frozentset(_value_and_type_iter(self.__args__)))

I'm not sure if frozenset is too restrictive in terms of the values it can work with. Right now PEP 586 disallows literals of mutable types, but only at type check time. The PEP also contains the following comment:

[...] the actual implementation of typing.Literal will not perform any checks at runtime. [...] This is partly to help us preserve flexibility in case we want to expand the scope of what Literal can be used for in the future [...]

Using frozenset would take away on that flexibility regarding literals of mutable types. Not sure if that's relevant though. I think we should wait for @gvanrossum to comment on this.

@gvanrossum
Copy link
Member

Whoa, this is a bug. It not allowed to have two objects that compare equal but have a different hash. So since Literal[1, 2] == Literal[2, 1], those two should have the same hash. I'm sorry I didn't catch this!

Using set() or frozenset() here is totally fine, we already use those in __eq__. I'd use set().

@uriyyo
Copy link
Member Author

uriyyo commented Nov 18, 2020

@gvanrossum Should we create a separate issue or just open a new PR that will point to the same issue as this PR?

@gvanrossum
Copy link
Member

gvanrossum commented Nov 18, 2020 via email

miss-islington pushed a commit that referenced this pull request Nov 19, 2020
Fix hash implementation of `typing.Literal`.

Update docs regarding `typing.Litaral` caching.

Base implementation was done in PR #23294.
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Nov 19, 2020
Fix hash implementation of `typing.Literal`.

Update docs regarding `typing.Litaral` caching.

Base implementation was done in PR pythonGH-23294.
(cherry picked from commit 1b54077)

Co-authored-by: Yurii Karabas <[email protected]>
miss-islington added a commit that referenced this pull request Nov 19, 2020
Fix hash implementation of `typing.Literal`.

Update docs regarding `typing.Litaral` caching.

Base implementation was done in PR GH-23294.
(cherry picked from commit 1b54077)

Co-authored-by: Yurii Karabas <[email protected]>
adorilson pushed a commit to adorilson/cpython that referenced this pull request Mar 13, 2021
…23294)

Literal equality no longer depends on the order of arguments.

Fix issue related to `typing.Literal` caching by adding `typed` parameter to `typing._tp_cache` function.

Add deduplication of `typing.Literal` arguments.
adorilson pushed a commit to adorilson/cpython that referenced this pull request Mar 13, 2021
Fix hash implementation of `typing.Literal`.

Update docs regarding `typing.Litaral` caching.

Base implementation was done in PR python#23294.
kraj pushed a commit to YoeDistro/poky that referenced this pull request Jun 1, 2023
Changelog:
============
-  Fix use of @deprecated on classes with __new__ but no __init__.
-  Fix regression in version 4.6.1 where comparing a generic class against a
   runtime-checkable protocol using isinstance() would cause AttributeError to
   be raised if using Python 3.7.
-  Change deprecated @runtime to formal API @runtime_checkable in the error message.
-  Fix regression in 4.6.0 where attempting to define a Protocol that was generic
   over a ParamSpec or a TypeVarTuple would cause TypeError to be raised.
-  typing_extensions is now documented at https://typing-extensions.readthedocs.io/en/latest/.
-  Add typing_extensions.Buffer, a marker class for buffer types, as proposed
   by PEP 688. Equivalent to collections.abc.Buffer in Python 3.12.
-  Backport two CPython PRs fixing various issues with typing.Literal:
   python/cpython#23294 and python/cpython#23383. Both CPython PRs were originally,
   and both were backported to Python >=3.9.1, but no earlier.
-  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.)
-  Literal is now reimplemented on all Python versions <= 3.10.0.
-  Backport CPython PR 26067, ensuring that isinstance() calls on protocols raise
   TypeError when the protocol is not decorated with @runtime_checkable.
-  Backport several significant performance improvements to runtime-checkable protocols
   that have been made in Python 3.12 (see python/cpython#74690 for details).
-  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.
-  isinstance() checks against runtime-checkable protocols now use inspect.getattr_static()
   rather than hasattr() to lookup whether attributes exist (backporting python/cpython#103034).
-  Backport the ability to define __init__ methods on Protocol classes, a change
   made in Python 3.11 (originally implemented in python/cpython#31628
-  Speedup isinstance(3, typing_extensions.SupportsIndex) by >10x on Python <3.12.
-  Add typing_extensions versions of SupportsInt, SupportsFloat, SupportsComplex,
   SupportsBytes, SupportsAbs and SupportsRound. These have the same semantics as
   the versions from the typing module, but isinstance() checks against the
   typing_extensions versions are >10x faster at runtime on Python <3.12.
-  Add __orig_bases__ to non-generic TypedDicts, call-based TypedDicts, and call-based NamedTuples.
-  Add typing_extensions.get_original_bases, a backport of types.get_original_bases,
   introduced in Python 3.12 (CPython PR python/cpython#101827, originally
-  This function should always produce correct results when called on classes
   constructed using features from typing_extensions.
-  Constructing a call-based TypedDict using keyword arguments for the fields
   now causes a DeprecationWarning to be emitted. This matches the behaviour
   of typing.TypedDict on 3.11 and 3.12.
-  Backport the implementation of NewType from 3.10 (where it is implemented as
   a class rather than a function). This allows user-defined NewTypes to be pickled.
-  Fix tests and import on Python 3.12, where typing.TypeVar can no longer be subclassed.
-  Add typing_extensions.TypeAliasType, a backport of typing.TypeAliasType from PEP 695.
-  Backport changes to the repr of typing.Unpack that were made in order
   to implement PEP 692 (backport of python/cpython#104048).

(From OE-Core rev: 2b1d07c7deb4f0247765bc737fb11a1747143edf)

Signed-off-by: Wang Mingyu <[email protected]>
Signed-off-by: Alexandre Belloni <[email protected]>
rpurdie pushed a commit to yoctoproject/poky that referenced this pull request Jun 2, 2023
Changelog:
============
-  Fix use of @deprecated on classes with __new__ but no __init__.
-  Fix regression in version 4.6.1 where comparing a generic class against a
   runtime-checkable protocol using isinstance() would cause AttributeError to
   be raised if using Python 3.7.
-  Change deprecated @runtime to formal API @runtime_checkable in the error message.
-  Fix regression in 4.6.0 where attempting to define a Protocol that was generic
   over a ParamSpec or a TypeVarTuple would cause TypeError to be raised.
-  typing_extensions is now documented at https://typing-extensions.readthedocs.io/en/latest/.
-  Add typing_extensions.Buffer, a marker class for buffer types, as proposed
   by PEP 688. Equivalent to collections.abc.Buffer in Python 3.12.
-  Backport two CPython PRs fixing various issues with typing.Literal:
   python/cpython#23294 and python/cpython#23383. Both CPython PRs were originally,
   and both were backported to Python >=3.9.1, but no earlier.
-  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.)
-  Literal is now reimplemented on all Python versions <= 3.10.0.
-  Backport CPython PR 26067, ensuring that isinstance() calls on protocols raise
   TypeError when the protocol is not decorated with @runtime_checkable.
-  Backport several significant performance improvements to runtime-checkable protocols
   that have been made in Python 3.12 (see python/cpython#74690 for details).
-  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.
-  isinstance() checks against runtime-checkable protocols now use inspect.getattr_static()
   rather than hasattr() to lookup whether attributes exist (backporting python/cpython#103034).
-  Backport the ability to define __init__ methods on Protocol classes, a change
   made in Python 3.11 (originally implemented in python/cpython#31628
-  Speedup isinstance(3, typing_extensions.SupportsIndex) by >10x on Python <3.12.
-  Add typing_extensions versions of SupportsInt, SupportsFloat, SupportsComplex,
   SupportsBytes, SupportsAbs and SupportsRound. These have the same semantics as
   the versions from the typing module, but isinstance() checks against the
   typing_extensions versions are >10x faster at runtime on Python <3.12.
-  Add __orig_bases__ to non-generic TypedDicts, call-based TypedDicts, and call-based NamedTuples.
-  Add typing_extensions.get_original_bases, a backport of types.get_original_bases,
   introduced in Python 3.12 (CPython PR python/cpython#101827, originally
-  This function should always produce correct results when called on classes
   constructed using features from typing_extensions.
-  Constructing a call-based TypedDict using keyword arguments for the fields
   now causes a DeprecationWarning to be emitted. This matches the behaviour
   of typing.TypedDict on 3.11 and 3.12.
-  Backport the implementation of NewType from 3.10 (where it is implemented as
   a class rather than a function). This allows user-defined NewTypes to be pickled.
-  Fix tests and import on Python 3.12, where typing.TypeVar can no longer be subclassed.
-  Add typing_extensions.TypeAliasType, a backport of typing.TypeAliasType from PEP 695.
-  Backport changes to the repr of typing.Unpack that were made in order
   to implement PEP 692 (backport of python/cpython#104048).

(From OE-Core rev: a37154b9166323d05cca970ebb37bee0d5250893)

Signed-off-by: Wang Mingyu <[email protected]>
Signed-off-by: Alexandre Belloni <[email protected]>
Signed-off-by: Richard Purdie <[email protected]>
halstead pushed a commit to openembedded/openembedded-core that referenced this pull request Jun 2, 2023
Changelog:
============
-  Fix use of @deprecated on classes with __new__ but no __init__.
-  Fix regression in version 4.6.1 where comparing a generic class against a
   runtime-checkable protocol using isinstance() would cause AttributeError to
   be raised if using Python 3.7.
-  Change deprecated @runtime to formal API @runtime_checkable in the error message.
-  Fix regression in 4.6.0 where attempting to define a Protocol that was generic
   over a ParamSpec or a TypeVarTuple would cause TypeError to be raised.
-  typing_extensions is now documented at https://typing-extensions.readthedocs.io/en/latest/.
-  Add typing_extensions.Buffer, a marker class for buffer types, as proposed
   by PEP 688. Equivalent to collections.abc.Buffer in Python 3.12.
-  Backport two CPython PRs fixing various issues with typing.Literal:
   python/cpython#23294 and python/cpython#23383. Both CPython PRs were originally,
   and both were backported to Python >=3.9.1, but no earlier.
-  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.)
-  Literal is now reimplemented on all Python versions <= 3.10.0.
-  Backport CPython PR 26067, ensuring that isinstance() calls on protocols raise
   TypeError when the protocol is not decorated with @runtime_checkable.
-  Backport several significant performance improvements to runtime-checkable protocols
   that have been made in Python 3.12 (see python/cpython#74690 for details).
-  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.
-  isinstance() checks against runtime-checkable protocols now use inspect.getattr_static()
   rather than hasattr() to lookup whether attributes exist (backporting python/cpython#103034).
-  Backport the ability to define __init__ methods on Protocol classes, a change
   made in Python 3.11 (originally implemented in python/cpython#31628
-  Speedup isinstance(3, typing_extensions.SupportsIndex) by >10x on Python <3.12.
-  Add typing_extensions versions of SupportsInt, SupportsFloat, SupportsComplex,
   SupportsBytes, SupportsAbs and SupportsRound. These have the same semantics as
   the versions from the typing module, but isinstance() checks against the
   typing_extensions versions are >10x faster at runtime on Python <3.12.
-  Add __orig_bases__ to non-generic TypedDicts, call-based TypedDicts, and call-based NamedTuples.
-  Add typing_extensions.get_original_bases, a backport of types.get_original_bases,
   introduced in Python 3.12 (CPython PR python/cpython#101827, originally
-  This function should always produce correct results when called on classes
   constructed using features from typing_extensions.
-  Constructing a call-based TypedDict using keyword arguments for the fields
   now causes a DeprecationWarning to be emitted. This matches the behaviour
   of typing.TypedDict on 3.11 and 3.12.
-  Backport the implementation of NewType from 3.10 (where it is implemented as
   a class rather than a function). This allows user-defined NewTypes to be pickled.
-  Fix tests and import on Python 3.12, where typing.TypeVar can no longer be subclassed.
-  Add typing_extensions.TypeAliasType, a backport of typing.TypeAliasType from PEP 695.
-  Backport changes to the repr of typing.Unpack that were made in order
   to implement PEP 692 (backport of python/cpython#104048).

Signed-off-by: Wang Mingyu <[email protected]>
Signed-off-by: Alexandre Belloni <[email protected]>
renovate bot referenced this pull request in allenporter/flux-local Jun 3, 2023
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [typing-extensions](https://togithub.com/python/typing_extensions)
([changelog](https://togithub.com/python/typing_extensions/blob/main/CHANGELOG.md))
| `==4.5.0` -> `==4.6.3` |
[![age](https://badges.renovateapi.com/packages/pypi/typing-extensions/4.6.3/age-slim)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://badges.renovateapi.com/packages/pypi/typing-extensions/4.6.3/adoption-slim)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://badges.renovateapi.com/packages/pypi/typing-extensions/4.6.3/compatibility-slim/4.5.0)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://badges.renovateapi.com/packages/pypi/typing-extensions/4.6.3/confidence-slim/4.5.0)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>python/typing_extensions</summary>

###
[`v4.6.3`](https://togithub.com/python/typing_extensions/blob/HEAD/CHANGELOG.md#Release-463-June-1-2023)

[Compare
Source](https://togithub.com/python/typing_extensions/compare/4.6.2...4.6.3)

-   Fix a regression introduced in v4.6.0 in the implementation of
    runtime-checkable protocols. The regression meant
that doing `class Foo(X, typing_extensions.Protocol)`, where `X` was a
class that
    had `abc.ABCMeta` as its metaclass, would then cause subsequent
    `isinstance(1, X)` calls to erroneously raise `TypeError`. Patch by
Alex Waygood (backporting the
CPython[https://github.com/python/cpython/pull/105152](https://togithub.com/python/cpython/pull/105152)l/105152).
-   Sync the repository's LICENSE file with that of CPython.
    `typing_extensions` is distributed under the same license as
    CPython itself.
- Skip a problematic test on Python 3.12.0b1. The test fails on 3.12.0b1
due to
    a bug in CPython, which will be fixed in 3.12.0b2. The
    `typing_extensions` test suite now passes on 3.12.0b1.

###
[`v4.6.2`](https://togithub.com/python/typing_extensions/blob/HEAD/CHANGELOG.md#Release-462-May-25-2023)

[Compare
Source](https://togithub.com/python/typing_extensions/compare/4.6.1...4.6.2)

- Fix use of `@deprecated` on classes with `__new__` but no `__init__`.
    Patch by Jelle Zijlstra.
- Fix regression in version 4.6.1 where comparing a generic class
against a
runtime-checkable protocol using `isinstance()` would cause
`AttributeError`
    to be raised if using Python 3.7.

###
[`v4.6.1`](https://togithub.com/python/typing_extensions/blob/HEAD/CHANGELOG.md#Release-461-May-23-2023)

[Compare
Source](https://togithub.com/python/typing_extensions/compare/4.6.0...4.6.1)

- Change deprecated `@runtime` to formal API `@runtime_checkable` in the
error
    message. Patch by Xuehai Pan.
- Fix regression in 4.6.0 where attempting to define a `Protocol` that
was
generic over a `ParamSpec` or a `TypeVarTuple` would cause `TypeError`
to be
    raised. Patch by Alex Waygood.

###
[`v4.6.0`](https://togithub.com/python/typing_extensions/blob/HEAD/CHANGELOG.md#Release-460-May-22-2023)

[Compare
Source](https://togithub.com/python/typing_extensions/compare/4.5.0...4.6.0)

-   `typing_extensions` is now documented at
https://typing-extensions.readthedocs.io/en/latest/. Patch by Jelle
Zijlstra.
- Add `typing_extensions.Buffer`, a marker class for buffer types, as
proposed
by PEP 688. Equivalent to `collections.abc.Buffer` in Python 3.12. Patch
by
    Jelle Zijlstra.
- Backport two CPython PRs fixing various issues with `typing.Literal`:

[https://github.com/python/cpython/pull/23294](https://togithub.com/python/cpython/pull/23294)3294
[https://github.com/python/cpython/pull/23383](https://togithub.com/python/cpython/pull/23383)ll/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.)
-   `Literal` is now reimplemented on all Python versions <= 3.10.0. The
`typing_extensions` version does not suffer from the bug that was fixed
in

[https://github.com/python/cpython/pull/29334](https://togithub.com/python/cpython/pull/29334)9334.
(The CPython bugfix was
    backported to CPython 3.10.1 and 3.9.8, but no earlier.)
- Backport [CPython PR
26067](https://togithub.com/python/cpython/pull/26067)
    (originally by Yurii Karabas), ensuring that `isinstance()` calls on
    protocols raise `TypeError` when the protocol is not decorated with
    `@runtime_checkable`. Patch by Alex Waygood.
- Backport several significant performance improvements to
runtime-checkable
protocols that have been made in Python 3.12
([https://github.com/python/cpython/issues/74690](https://togithub.com/python/cpython/issues/74690)es/74690
for details). Patch by Alex
    Waygood.

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"](https://docs.python.org/3.12/whatsnew/3.12.html#typing)
    for more details.
-   `isinstance()` checks against runtime-checkable protocols now use
    `inspect.getattr_static()` rather than `hasattr()` to lookup whether
attributes exist
(backport[https://github.com/python/cpython/pull/103034](https://togithub.com/python/cpython/pull/103034)3034).
    This means that descriptors and `__getattr__` methods are no longer
unexpectedly evaluated during `isinstance()` checks against
runtime-checkable
protocols. However, it may also mean that some objects which used to be
considered instances of a runtime-checkable protocol on older versions
of
`typing_extensions` may no longer be considered instances of that
protocol
using the new release, and vice versa. Most users are unlikely to be
affected
    by this change. Patch by Alex Waygood.
- Backport the ability to define `__init__` methods on Protocol classes,
a
change made in Python 3.11 (originally
implemented[https://github.com/python/cpython/pull/31628](https://togithub.com/python/cpython/pull/31628)ll/31628
by Adrian Garcia Badaracco).
    Patch by Alex Waygood.
- Speedup `isinstance(3, typing_extensions.SupportsIndex)` by >10x on
Python
    <3.12. Patch by Alex Waygood.
-   Add `typing_extensions` versions of `SupportsInt`, `SupportsFloat`,
`SupportsComplex`, `SupportsBytes`, `SupportsAbs` and `SupportsRound`.
These
have the same semantics as the versions from the `typing` module, but
`isinstance()` checks against the `typing_extensions` versions are >10x
faster
    at runtime on Python <3.12. Patch by Alex Waygood.
- Add `__orig_bases__` to non-generic TypedDicts, call-based TypedDicts,
and
call-based NamedTuples. Other TypedDicts and NamedTuples already had the
attribute.
    Patch by Adrian Garcia Badaracco.
-   Add `typing_extensions.get_original_bases`, a backport of

[`types.get_original_bases`](https://docs.python.org/3.12/library/types.html#types.get_original_bases),
introduced in Python 3.12
(CPython[https://github.com/python/cpython/pull/101827](https://togithub.com/python/cpython/pull/101827)l/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.
- Constructing a call-based `TypedDict` using keyword arguments for the
fields
now causes a `DeprecationWarning` to be emitted. This matches the
behaviour
    of `typing.TypedDict` on 3.11 and 3.12.
- Backport the implementation of `NewType` from 3.10 (where it is
implemented
as a class rather than a function). This allows user-defined `NewType`s
to be
    pickled. Patch by Alex Waygood.
- Fix tests and import on Python 3.12, where `typing.TypeVar` can no
longer be
    subclassed. Patch by Jelle Zijlstra.
- Add `typing_extensions.TypeAliasType`, a backport of
`typing.TypeAliasType`
    from PEP 695. Patch by Jelle Zijlstra.
- Backport changes to the repr of `typing.Unpack` that were made in
order to
    implement [PEP 692](https://peps.python.org/pep-0692/) (backport of

[https://github.com/python/cpython/pull/104048](https://togithub.com/python/cpython/pull/104048)4048).
Patch by Alex Waygood.

</details>

---

### 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.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://app.renovatebot.com/dashboard#github/allenporter/flux-local).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNS4xMDUuMiIsInVwZGF0ZWRJblZlciI6IjM1LjEwNS4yIiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9-->

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
Changelog:
============
-  Fix use of @deprecated on classes with __new__ but no __init__.
-  Fix regression in version 4.6.1 where comparing a generic class against a
   runtime-checkable protocol using isinstance() would cause AttributeError to
   be raised if using Python 3.7.
-  Change deprecated @runtime to formal API @runtime_checkable in the error message.
-  Fix regression in 4.6.0 where attempting to define a Protocol that was generic
   over a ParamSpec or a TypeVarTuple would cause TypeError to be raised.
-  typing_extensions is now documented at https://typing-extensions.readthedocs.io/en/latest/.
-  Add typing_extensions.Buffer, a marker class for buffer types, as proposed
   by PEP 688. Equivalent to collections.abc.Buffer in Python 3.12.
-  Backport two CPython PRs fixing various issues with typing.Literal:
   python/cpython#23294 and python/cpython#23383. Both CPython PRs were originally,
   and both were backported to Python >=3.9.1, but no earlier.
-  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.)
-  Literal is now reimplemented on all Python versions <= 3.10.0.
-  Backport CPython PR 26067, ensuring that isinstance() calls on protocols raise
   TypeError when the protocol is not decorated with @runtime_checkable.
-  Backport several significant performance improvements to runtime-checkable protocols
   that have been made in Python 3.12 (see python/cpython#74690 for details).
-  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.
-  isinstance() checks against runtime-checkable protocols now use inspect.getattr_static()
   rather than hasattr() to lookup whether attributes exist (backporting python/cpython#103034).
-  Backport the ability to define __init__ methods on Protocol classes, a change
   made in Python 3.11 (originally implemented in python/cpython#31628
-  Speedup isinstance(3, typing_extensions.SupportsIndex) by >10x on Python <3.12.
-  Add typing_extensions versions of SupportsInt, SupportsFloat, SupportsComplex,
   SupportsBytes, SupportsAbs and SupportsRound. These have the same semantics as
   the versions from the typing module, but isinstance() checks against the
   typing_extensions versions are >10x faster at runtime on Python <3.12.
-  Add __orig_bases__ to non-generic TypedDicts, call-based TypedDicts, and call-based NamedTuples.
-  Add typing_extensions.get_original_bases, a backport of types.get_original_bases,
   introduced in Python 3.12 (CPython PR python/cpython#101827, originally
-  This function should always produce correct results when called on classes
   constructed using features from typing_extensions.
-  Constructing a call-based TypedDict using keyword arguments for the fields
   now causes a DeprecationWarning to be emitted. This matches the behaviour
   of typing.TypedDict on 3.11 and 3.12.
-  Backport the implementation of NewType from 3.10 (where it is implemented as
   a class rather than a function). This allows user-defined NewTypes to be pickled.
-  Fix tests and import on Python 3.12, where typing.TypeVar can no longer be subclassed.
-  Add typing_extensions.TypeAliasType, a backport of typing.TypeAliasType from PEP 695.
-  Backport changes to the repr of typing.Unpack that were made in order
   to implement PEP 692 (backport of python/cpython#104048).

(From OE-Core rev: a37154b9166323d05cca970ebb37bee0d5250893)

Signed-off-by: Wang Mingyu <[email protected]>
Signed-off-by: Alexandre Belloni <[email protected]>
Signed-off-by: Richard Purdie <[email protected]>
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.

8 participants