Visitar URL original
Update heapq.py - Works with both python2 and python3. by MKAMANOJ · Pull Request #21951 · python/cpython · GitHub
The Wayback Machine - https://web.archive.org/web/20221223195220/https://github.com/python/cpython/pull/21951
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

Update heapq.py - Works with both python2 and python3. #21951

Closed
wants to merge 1 commit into from

Conversation

MKAMANOJ
Copy link

@MKAMANOJ MKAMANOJ commented Aug 25, 2020

Comparison between string and tuple is not supported in python3 but in python 2. This change works in both cases.
I had faced the https://stackoverflow.com/questions/63570226/typeerror-on-heapq-heapop-on-python3-but-but-working-in-python2/63572303#63572303
issue and solved it using this technique.

Comparison between string and tuple is not supported in python3 but in python 2.  This change works in both cases.
I had faced the https://stackoverflow.com/questions/63570226/typeerror-on-heapq-heapop-on-python3-but-but-working-in-python2/63572303#63572303
issue and solved it using this technique.
@the-knights-who-say-ni
Copy link

the-knights-who-say-ni commented Aug 25, 2020

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept this contribution by verifying everyone involved has signed the PSF contributor agreement (CLA).

Recognized GitHub username

We couldn't find a bugs.python.org (b.p.o) account corresponding to the following GitHub usernames:

@MKAMANOJ

This might be simply due to a missing "GitHub Name" entry in one's b.p.o account settings. This is necessary for legal reasons before we can look at this contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.

You can check yourself to see if the CLA has been received.

Thanks again for the contribution, we look forward to reviewing it!

@iritkatriel
Copy link
Member

iritkatriel commented Aug 25, 2020

Hi Manoj, Please create a ticket in https://bugs.python.org/ explaining what the issue you are solving is exactly. Include code snippets to reproduce the problem. You would also need to include tests in this pull request. See the developer's guide here for more details: https://devguide.python.org/

@rhettinger rhettinger self-assigned this Aug 28, 2020
@rhettinger
Copy link
Contributor

rhettinger commented Aug 28, 2020

Sorry Manoj, but this is a non-starter.

  • It changes the API in a way that breaks existing code.
  • It is a feature that str and tuple are non-comparable.
  • That error is telling you that your original code had errors in its design.
  • Even sorted() would give you the same exception:
>>> trees = [(4, 'N'), (4, (2, (1, 'K'), (1, '50')), (2, (1, '38'), (1, '35')))]
>>> sorted(trees)
Traceback (most recent call last):
 ...
TypeError: '<' not supported between instances of 'tuple' and 'str'
[(4, 'N'), (4, (2, (1, 'K'), (1, '50')), (2, (1, '38'), (1, '35')))]

@rhettinger rhettinger closed this Aug 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants