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 — GH-84783: Make the slice object hashable by furkanonder · Pull Request #101264 · python/cpython

Conversation

@furkanonder

@furkanonder furkanonder commented Jan 23, 2023 •
edited by bedevere-bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor
  • Issue: slice not hashable #84783

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
furkanonder added 2 commits January 23, 2023 23:03
@furkanonder
fix the typo in the tuplehash func's comment
61c8048
@furkanonder
make hashable the slice
ef22a92
@bedevere-bot bedevere-bot added the awaiting review label Jan 23, 2023
@bedevere-bot bedevere-bot mentioned this pull request Jan 23, 2023
slice not hashable #84783
Closed
furkanonder added 2 commits January 23, 2023 20:09
@furkanonder
Merge branch 'main' into issue-84783
12c2488
@furkanonder
Merge branch 'main' into issue-84783
6dd9926
rhettinger
rhettinger requested changes Feb 5, 2023
View reviewed changes
Comment thread Objects/sliceobject.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot removed the awaiting review label Feb 5, 2023
@bedevere-bot

bedevere-bot commented Feb 5, 2023

Copy link
Copy Markdown

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot added the awaiting changes label Feb 5, 2023
rhettinger
rhettinger approved these changes Feb 5, 2023
View reviewed changes
@bedevere-bot bedevere-bot added awaiting merge and removed awaiting changes labels Feb 5, 2023
rhettinger
rhettinger requested changes Feb 5, 2023
View reviewed changes

@rhettinger rhettinger left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do need to add a NEWS blurb and a versionchanged entry to the docs.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-bot bedevere-bot added awaiting changes and removed awaiting merge labels Feb 5, 2023
@bedevere-bot

bedevere-bot commented Feb 5, 2023

Copy link
Copy Markdown

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rhettinger

rhettinger commented Feb 5, 2023

Copy link
Copy Markdown
Contributor

We're getting some test failures:

======================================================================
[3683](https://github.com/python/cpython/actions/runs/4006251040/jobs/6877559173#step:7:3684)
ERROR: test_sequence_del_slice (test.test_capi.test_misc.CAPITest.test_sequence_del_slice)
[3684](https://github.com/python/cpython/actions/runs/4006251040/jobs/6877559173#step:7:3685)
----------------------------------------------------------------------
[3685](https://github.com/python/cpython/actions/runs/4006251040/jobs/6877559173#step:7:3686)
Traceback (most recent call last):
[3686](https://github.com/python/cpython/actions/runs/4006251040/jobs/6877559173#step:7:3687)
  File "/Users/runner/work/cpython/cpython/Lib/test/test_capi/test_misc.py", line 459, in test_sequence_del_slice
[3687](https://github.com/python/cpython/actions/runs/4006251040/jobs/6877559173#step:7:3688)
    _testcapi.sequence_del_slice(mapping, 1, 3)
[3688](https://github.com/python/cpython/actions/runs/4006251040/jobs/6877559173#step:7:3689)
KeyError: slice(1, 3, None)
[3689](https://github.com/python/cpython/actions/runs/4006251040/jobs/6877559173#step:7:3690)

[3690](https://github.com/python/cpython/actions/runs/4006251040/jobs/6877559173#step:7:3691)
======================================================================
[3691](https://github.com/python/cpython/actions/runs/4006251040/jobs/6877559173#step:7:3692)
FAIL: test_sequence_set_slice (test.test_capi.test_misc.CAPITest.test_sequence_set_slice)
[3692](https://github.com/python/cpython/actions/runs/4006251040/jobs/6877559173#step:7:3693)
----------------------------------------------------------------------
[3693](https://github.com/python/cpython/actions/runs/4006251040/jobs/6877559173#step:7:3694)
Traceback (most recent call last):
[3694](https://github.com/python/cpython/actions/runs/4006251040/jobs/6877559173#step:7:3695)
  File "/Users/runner/work/cpython/cpython/Lib/test/test_capi/test_misc.py", line 419, in test_sequence_set_slice
[3695](https://github.com/python/cpython/actions/runs/4006251040/jobs/6877559173#step:7:3696)
    with self.assertRaises(TypeError):
[3696](https://github.com/python/cpython/actions/runs/4006251040/jobs/6877559173#step:7:3697)
AssertionError: TypeError not raised
[3697](https://github.com/python/cpython/actions/runs/4006251040/jobs/6877559173#step:7:3698)
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

rhettinger
rhettinger reviewed Feb 5, 2023
View reviewed changes
Comment thread Objects/sliceobject.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

@OTheDev

OTheDev commented Feb 11, 2023

Copy link
Copy Markdown
Contributor

It looks like the following test needs to be removed or changed as the expected behaviour would now be a KeyError as slice objects would now be valid as keys.

cpython/Lib/test/test_capi/test_misc.py

Lines 457 to 460 in b652d40

mapping = {1: 'a', 2: 'b', 3: 'c'}
with self.assertRaises(TypeError):
_testcapi.sequence_del_slice(mapping, 1, 3)
self.assertEqual(mapping, {1: 'a', 2: 'b', 3: 'c'})

The following test can probably be modified to reflect the fact that mapping[1:3] = 'xy' would be valid and that

mapping == {1: 'a', 2: 'b', 3: 'c', slice(1, 3, None): 'xy'}

is true afterwards:

cpython/Lib/test/test_capi/test_misc.py

Lines 418 to 421 in b652d40

mapping = {1: 'a', 2: 'b', 3: 'c'}
with self.assertRaises(TypeError):
_testcapi.sequence_set_slice(mapping, 1, 3, 'xy')
self.assertEqual(mapping, {1: 'a', 2: 'b', 3: 'c'})

furkanonder and rhettinger reacted with thumbs up emoji
All reactions
  • 👍 2 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

furkanonder and others added 3 commits February 12, 2023 01:45
@furkanonder
fix failed slice's test cases
886bfff
@furkanonder
Merge branch 'main' into issue-84783
2971147
@blurb-it
📜🤖 Added by blurb_it.
093bf38
OTheDev
OTheDev reviewed Feb 11, 2023
View reviewed changes
Comment thread Lib/test/test_slice.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@furkanonder
Add version changed to slice's doc
159f3f2
OTheDev
OTheDev reviewed Feb 12, 2023
View reviewed changes
Comment thread Doc/library/functions.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

@OTheDev

OTheDev commented Feb 12, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Please correct me if I am wrong, but it looks like test_doctest() is failing because

cpython/Lib/test/test_doctest.py

Line 710 in 3eb12df

>>> 825 < len(tests) < 845 # approximate number of objects with docstrings
needs to be relaxed (increased) a bit. It seems to just be at the limit. Non-debug build passes (with len(tests) at 844) but debug build adds one to len(tests) (making it 845). Looking at the commit history, it looks like it needs modifying every now and then.

@iritkatriel Apologies, but it looks like you were the last to modify this line. Does this sound about right to you?

EDIT: I think I've figured it out (below)!

furkanonder reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@OTheDev

OTheDev commented Feb 12, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

@furkanonder

I think I understand now why test_doctests() is failing.

On my system, if I clone main, build it normally (non-debug), and compute len(tests) (see previous comment), I get 843.

Now, if I clone your branch, build it normally (non-debug), I get 844 instead. The extra entry to tests is <DocTest builtins.slice.__hash__ from builtins:None (no examples)>, which isn't an element of tests on main.

Now, running the tests (on your branch) with non-debug mode succeeds on my system.

Once we build with --with-pydebug, however, this adds an additional entry to tests, namely, <DocTest builtins.set.test_c_api from builtins:None (no examples)> (whether on your branch or main), making the number on your branch 845, which makes

cpython/Lib/test/test_doctest.py

Line 710 in 3eb12df

>>> 825 < len(tests) < 845 # approximate number of objects with docstrings

fail.

So, I think what needs to be done now is for you to modify that line in test_doctest.py, say, to

>>> 830 < len(tests) < 850

I have verified that test_doctests() passes after this change (both on non-debug and debug builds).

For reference:

>>> import builtins, doctest
>>> tests = doctest.DocTestFinder().find(builtins)
furkanonder reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

OTheDev and others added 2 commits February 12, 2023 21:36
@OTheDev
Update test_doctest.py
0c78cfc
@furkanonder @OTheDev
Update Doc/library/functions.rst
cff08dd
Co-authored-by: Owain Davies <[email protected]>
furkanonder added 4 commits February 12, 2023 20:42
@furkanonder
Merge branch 'main' into issue-84783
ea55931
@furkanonder
Update version changed to slice's doc
f0302bf
@furkanonder
Merge pull request #1 from OTheDev/patch-1
2c76491
Update test_doctest.py
@furkanonder
Add more testcases for slice's hash
cbd1527
@furkanonder
furkanonder requested a review from OTheDev February 12, 2023 23:02
OTheDev
OTheDev reviewed Feb 13, 2023
View reviewed changes
Comment thread Lib/test/test_slice.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@furkanonder
update testcases for slice's hash
9f55e46
OTheDev
OTheDev reviewed Feb 13, 2023
View reviewed changes
Comment thread Lib/test/test_slice.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@rhettinger
rhettinger merged commit 61f1e67 into python:main Feb 19, 2023
@bedevere-bot bedevere-bot removed the awaiting changes label Feb 19, 2023
carljm added a commit to carljm/cpython that referenced this pull request Feb 20, 2023
@carljm
Merge branch 'main' into inlinecomp2
9f0fc5b
* main: (60 commits)
  pythongh-102056: Fix a few bugs in error handling of exception printing code (python#102078)
  pythongh-102011: use sys.exception() instead of sys.exc_info() in docs where possible (python#102012)
  pythongh-101566: Sync with zipp 3.14. (pythonGH-102018)
  pythonGH-99818: improve the documentation for zipfile.Path and Traversable (pythonGH-101589)
  pythongh-88233: zipfile: handle extras after a zip64 extra (pythonGH-96161)
  pythongh-101981: Apply HOMEBREW related environment variables (pythongh-102074)
  pythongh-101907: Stop using `_Py_OPCODE` and `_Py_OPARG` macros (pythonGH-101912)
  pythongh-101819: Adapt _io types to heap types, batch 1 (pythonGH-101949)
  pythongh-101981: Build macOS as recommended by the devguide (pythonGH-102070)
  pythongh-97786: Fix compiler warnings in pytime.c (python#101826)
  pythongh-101578: Amend PyErr_{Set,Get}RaisedException docs (python#101962)
  Misc improvements to the float tutorial (pythonGH-102052)
  pythongh-85417: Clarify behaviour on branch cuts in cmath module (python#102046)
  pythongh-100425: Update tutorial docs related to sum() accuracy (FH-101854)
  Add missing 'is' to `cmath.log()` docstring (python#102049)
  pythongh-100210: Correct the comment link for unescaping HTML (python#100212)
  pythongh-97930: Also include subdirectory in makefile. (python#102030)
  pythongh-99735: Use required=True in argparse subparsers example (python#100927)
  Fix incorrectly documented attribute in csv docs (python#101250)
  pythonGH-84783: Make the slice object hashable (pythonGH-101264)
  ...
carljm added a commit to carljm/cpython that referenced this pull request Feb 22, 2023
@carljm
Merge branch 'main' into inlinecomp
544b30c
* main: (225 commits)
  pythongh-102056: Fix a few bugs in error handling of exception printing code (python#102078)
  pythongh-102011: use sys.exception() instead of sys.exc_info() in docs where possible (python#102012)
  pythongh-101566: Sync with zipp 3.14. (pythonGH-102018)
  pythonGH-99818: improve the documentation for zipfile.Path and Traversable (pythonGH-101589)
  pythongh-88233: zipfile: handle extras after a zip64 extra (pythonGH-96161)
  pythongh-101981: Apply HOMEBREW related environment variables (pythongh-102074)
  pythongh-101907: Stop using `_Py_OPCODE` and `_Py_OPARG` macros (pythonGH-101912)
  pythongh-101819: Adapt _io types to heap types, batch 1 (pythonGH-101949)
  pythongh-101981: Build macOS as recommended by the devguide (pythonGH-102070)
  pythongh-97786: Fix compiler warnings in pytime.c (python#101826)
  pythongh-101578: Amend PyErr_{Set,Get}RaisedException docs (python#101962)
  Misc improvements to the float tutorial (pythonGH-102052)
  pythongh-85417: Clarify behaviour on branch cuts in cmath module (python#102046)
  pythongh-100425: Update tutorial docs related to sum() accuracy (FH-101854)
  Add missing 'is' to `cmath.log()` docstring (python#102049)
  pythongh-100210: Correct the comment link for unescaping HTML (python#100212)
  pythongh-97930: Also include subdirectory in makefile. (python#102030)
  pythongh-99735: Use required=True in argparse subparsers example (python#100927)
  Fix incorrectly documented attribute in csv docs (python#101250)
  pythonGH-84783: Make the slice object hashable (pythonGH-101264)
  ...
Yhg1s added a commit to Yhg1s/cpython that referenced this pull request Mar 9, 2023
@Yhg1s
Document pythonGH-101264 (Make the slice object hashable) in What's New.
7c4a026
Yhg1s added a commit that referenced this pull request Mar 9, 2023
@Yhg1s
GH-84783: Document GH-101264 (Make the slice object hashable) in What…
58d761e
…'s New. (#102548)
furkanonder added a commit to furkanonder/cpython that referenced this pull request Mar 31, 2023
@furkanonder
Mention Author for pythonGH-101264 (Make the slice object hashable)
b1edad1
terryjreedy added a commit that referenced this pull request Mar 31, 2023
@furkanonder @terryjreedy
GH-84783: Mention Author for GH-101264 (make slices hashable) (#103146)
048d624
Will Bradshaw contributed original patch on bpo-40603.
---------

Co-authored-by: Terry Jan Reedy <[email protected]>
warsaw pushed a commit to warsaw/cpython that referenced this pull request Apr 11, 2023
@furkanonder @terryjreedy @warsaw
pythonGH-84783: Mention Author for pythonGH-101264 (make slices hasha…
7ef1570
…ble) (python#103146)

Will Bradshaw contributed original patch on bpo-40603.
---------

Co-authored-by: Terry Jan Reedy <[email protected]>
@zzzeek zzzeek mentioned this pull request May 22, 2023
python 3.12 slices are hashable, affects one area of Row for 1.4 only sqlalchemy/sqlalchemy#9819
Closed
@lithomas1 lithomas1 mentioned this pull request Jul 11, 2023
CI: Test Python 3.12 pandas-dev/pandas#53743
Merged
5 tasks
@sondreso sondreso mentioned this pull request Nov 24, 2023
Build python 3.12 wheels in Github Actions equinor/segyio#563
Merged
@tehunter tehunter mentioned this pull request Mar 27, 2024
BUG: Columns resulting from joining multiIndex dataFrame are incorrect in python 3.12.1 pandas-dev/pandas#57500
Closed
2 of 3 tasks
@davidosterberg davidosterberg mentioned this pull request Nov 21, 2024
Bug: loads broken on Python 3.12 and 3.13 victorazzo/abdbeam#8
Closed
@jaanerik jaanerik mentioned this pull request Jan 6, 2026
Refactor advanced subtensor pymc-devs/pytensor#1756
Merged
5 of 11 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@rhettinger rhettinger rhettinger requested changes
+1 more reviewer
@OTheDev OTheDev OTheDev left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@furkanonder @bedevere-bot @rhettinger @OTheDev
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.