GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Python removes negative ranges from dictionaries · Issue #103750 · python/cpython

Python removes negative ranges from dictionaries #103750

New issue
Copy link
New issue
Copy link
Closed
Closed
Python removes negative ranges from dictionaries#103750
Copy link
Labels
type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@wnakhleh
wnakhleh
opened on Apr 24, 2023
Issue body actions

Bug report

Python removes negative ranges from dictionaries

Example to reproduce:

print({range(16, 1): 0.5, range(32, 16): 0.5})

The expected output:

{range(16, 1): 0.5, range(32, 16): 0.5}

The actual output:

{range(16, 1): 0.5}

Your environment

  • CPython versions tested on: 3.10, 3.7.6
  • Operating system and architecture: WIN11+linux

Activity

  1. wnakhleh
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Apr 24, 2023
  2. Eclips4 commented on Apr 24, 2023

    @Eclips4
    Eclips4
    on Apr 24, 2023
    Member
    More actions

    However, this seems interesting:

    >>> a = {range(16, 1): 1}
    >>> a[range(32, 16)] = 2
    >>> a
    {range(16, 1): 2}
  3. Eclips4 commented on Apr 24, 2023

    @Eclips4
    Eclips4
    on Apr 24, 2023
    Member
    More actions

    Python removes negative ranges from dictionaries

    You misunderstood something. Python doesn't remove anything from dictionary.

    hash(range(32, 16)) == hash(range(16, 1))
    > True
    # And there's need a check for objects equality 
    range(32, 16) == range(16, 1)
    > True

    So, after these checks, Python decides to change the value of key.

  4. wnakhleh commented on Apr 24, 2023

    @wnakhleh
    wnakhleh
    on Apr 24, 2023
    Author
    More actions

    Since both are empty ranges...
    Thanks for the clarification

    Reacted by Kirill Podoprigora and Waad Nakhleh
  5. wnakhleh
    closed this as completedon Apr 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.