Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cython
Commits
e5a30318
Commit
e5a30318
authored
Mar 30, 2021
by
da-woods
Committed by
Stefan Behnel
Mar 30, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Avoid empty frozenset singleton on Python 3.10 (GH-4049)
See
https://github.com/cython/cython/issues/3919
parent
62c1802a
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
5 deletions
+7
-5
Cython/Utility/Builtins.c
Cython/Utility/Builtins.c
+2
-2
tests/run/set.pyx
tests/run/set.pyx
+5
-3
No files found.
Cython/Utility/Builtins.c
View file @
e5a30318
...
...
@@ -496,9 +496,9 @@ static CYTHON_INLINE PyObject* __Pyx_PyFrozenSet_New(PyObject* it) {
result
=
PyFrozenSet_New
(
it
);
if
(
unlikely
(
!
result
))
return
NULL
;
if
(
likely
(
PySet_GET_SIZE
(
result
)))
if
(
(
PY_VERSION_HEX
>=
0x031000A1
)
||
likely
(
PySet_GET_SIZE
(
result
)))
return
result
;
// empty frozenset is a singleton
// empty frozenset is a singleton
(on Python <3.10)
// seems wasteful, but CPython does the same
Py_DECREF
(
result
);
#endif
...
...
tests/run/set.pyx
View file @
e5a30318
...
...
@@ -417,7 +417,8 @@ def test_empty_frozenset():
True
>>> len(s)
0
>>> s is frozenset() # singleton!
>>> import sys
>>> sys.version_info >= (3, 10) or s is frozenset() # singleton (in Python < 3.10)!
True
"""
return
frozenset
()
...
...
@@ -430,7 +431,8 @@ def test_empty_frozenset():
)
def
test_singleton_empty_frozenset
():
"""
>>> test_singleton_empty_frozenset() # from CPython's test_set.py
>>> import sys
>>> test_singleton_empty_frozenset() if sys.version_info < (3, 10) else 1 # from CPython's test_set.py
1
"""
f
=
frozenset
()
...
...
@@ -438,7 +440,7 @@ def test_singleton_empty_frozenset():
frozenset
(),
frozenset
([]),
frozenset
(()),
frozenset
(
''
),
frozenset
(
range
(
0
)),
frozenset
(
frozenset
()),
frozenset
(
f
),
f
]
return
len
(
set
(
map
(
id
,
efs
)))
return
len
(
set
(
map
(
id
,
efs
)))
# note, only a singleton in Python <3.10
def
sorted
(
it
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment