classification
Title: Minor repr error in typing.TypeVar.__ror__()
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.10
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Jelle Zijlstra, gvanrossum, kj, larry, levkivskyi
Priority: low Keywords: patch

Created on 2021-04-08 11:09 by larry, last changed 2021-04-11 03:00 by gvanrossum. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 25339 merged Jelle Zijlstra, 2021-04-11 02:17
Messages (3)
msg390524 - (view) Author: Larry Hastings (larry) * (Python committer) Date: 2021-04-08 11:09
The implementation of the | operator for TypeVar objects is as follows:

    def __or__(self, right):
        return Union[self, right]

    def __ror__(self, right):
        return Union[self, right]

I think the implementation of __ror__ is ever-so-slightly inaccurate.  Shouldn't it be this?

    def __ror__(self, left):
        return Union[left, self]

I assume this wouldn't affect runtime behavior, as unions are sets and are presumably unordered.  The only observable difference should be in the repr() (and only then if both are non-None), as this reverses the elements.  The repr for Union does preserve the order of the elements it contains, so it's visible to the user there.
msg390540 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2021-04-08 18:26
Yes.--
--Guido (mobile)
msg390764 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2021-04-11 03:00
New changeset 9045919bfa820379a66ea67219f79ef6d9ecab49 by Jelle Zijlstra in branch 'master':
bpo-43772: Fix TypeVar.__ror__ (GH-25339)
https://github.com/python/cpython/commit/9045919bfa820379a66ea67219f79ef6d9ecab49
History
Date User Action Args
2021-04-11 03:00:19gvanrossumsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2021-04-11 03:00:09gvanrossumsetmessages: + msg390764
2021-04-11 02:17:09Jelle Zijlstrasetkeywords: + patch
nosy: + Jelle Zijlstra

pull_requests: + pull_request24074
stage: test needed -> patch review
2021-04-09 14:40:32kjsetnosy: + kj
2021-04-08 18:26:18gvanrossumsetmessages: + msg390540
2021-04-08 14:41:11xtreaksetnosy: + gvanrossum, levkivskyi
2021-04-08 11:09:29larrycreate