New submission from Larry Hastings <la...@hastings.org>:

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.

----------
components: Library (Lib)
messages: 390524
nosy: larry
priority: low
severity: normal
stage: test needed
status: open
title: Minor repr error in typing.TypeVar.__ror__()
type: behavior
versions: Python 3.10

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue43772>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to