-
Notifications
You must be signed in to change notification settings - Fork 198
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixing Dict memoization sorting before normalizing keys is unsafe'
- Loading branch information
1 parent
adf2f11
commit 11ff829
Showing
45 changed files
with
45 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import pytest | ||
import enum | ||
|
||
# Define an enum - collection of related consonants | ||
|
||
|
||
class Foo(enum.Enum): | ||
x = enum.auto() | ||
y = enum.auto() | ||
|
||
|
||
# Test function demonstrating the issue with unstable sorting when keys | ||
# are hashable but not comparable. | ||
|
||
|
||
def test_unstable_sorting(): | ||
# Functions | ||
def foo(): | ||
return 1 | ||
|
||
def bar(): | ||
return 2 | ||
|
||
# Dictionary with problematic keys | ||
d = {foo: 1, bar: 2} | ||
|
||
# Sort the dictionary, it should raise a TypeError | ||
with pytest.raises(TypeError): | ||
sorted(d) | ||
|
||
# Create a dictionary with enum keys | ||
d_enum = {Foo.x: 1, Foo.y: 2} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.