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

Minor repr error in typing.TypeVar.__ror__() #87938

Closed
larryhastings opened this issue Apr 8, 2021 · 3 comments
Closed

Minor repr error in typing.TypeVar.__ror__() #87938

larryhastings opened this issue Apr 8, 2021 · 3 comments
Labels
3.10 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@larryhastings
Copy link
Contributor

BPO 43772
Nosy @gvanrossum, @larryhastings, @ilevkivskyi, @JelleZijlstra, @Fidget-Spinner
PRs
  • bpo-43772: fix TypeVar.__ror__ #25339
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2021-04-11.03:00:19.295>
    created_at = <Date 2021-04-08.11:09:29.646>
    labels = ['type-bug', 'library', '3.10']
    title = 'Minor repr error in typing.TypeVar.__ror__()'
    updated_at = <Date 2021-04-11.03:00:19.295>
    user = 'https://github.com/larryhastings'

    bugs.python.org fields:

    activity = <Date 2021-04-11.03:00:19.295>
    actor = 'gvanrossum'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-04-11.03:00:19.295>
    closer = 'gvanrossum'
    components = ['Library (Lib)']
    creation = <Date 2021-04-08.11:09:29.646>
    creator = 'larry'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 43772
    keywords = ['patch']
    message_count = 3.0
    messages = ['390524', '390540', '390764']
    nosy_count = 5.0
    nosy_names = ['gvanrossum', 'larry', 'levkivskyi', 'JelleZijlstra', 'kj']
    pr_nums = ['25339']
    priority = 'low'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue43772'
    versions = ['Python 3.10']

    @larryhastings
    Copy link
    Contributor Author

    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.

    @larryhastings larryhastings added 3.10 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Apr 8, 2021
    @gvanrossum
    Copy link
    Member

    Yes.--
    --Guido (mobile)

    @gvanrossum
    Copy link
    Member

    New changeset 9045919 by Jelle Zijlstra in branch 'master':
    bpo-43772: Fix TypeVar.__ror__ (GH-25339)
    9045919

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.10 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants