pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/python/cpython/commit/4c3a0a35cd80a0abb9628dc8d4ade911fe2d5015

More on SF bug [#460020] bug or feature: unicode() and subclasses. · python/cpython@4c3a0a3 · GitHub
Skip to content

Commit 4c3a0a3

Browse files
committed
More on SF bug [#460020] bug or feature: unicode() and subclasses.
tuple(i) repaired to return a true tuple when i is an instance of a tuple subclass. Added PyTuple_CheckExact macro. PySequence_Tuple(): if a tuple-like object isn't exactly a tuple, it's not safe to return the object as-is -- make a new tuple of it instead.
1 parent caaff8d commit 4c3a0a3

3 files changed

Lines changed: 7 additions & 2 deletions

File tree

Include/tupleobject.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ typedef struct {
2727
extern DL_IMPORT(PyTypeObject) PyTuple_Type;
2828

2929
#define PyTuple_Check(op) PyObject_TypeCheck(op, &PyTuple_Type)
30+
#define PyTuple_CheckExact(op) ((op)->ob_type == &PyTuple_Type)
3031

3132
extern DL_IMPORT(PyObject *) PyTuple_New(int size);
3233
extern DL_IMPORT(int) PyTuple_Size(PyObject *);

Lib/test/test_descr.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1416,7 +1416,7 @@ def rev(self):
14161416
verify(v == t)
14171417
a = madtuple((1,2,3,4,5))
14181418
verify(tuple(a) == (1,2,3,4,5))
1419-
#XXX verify(tuple(a).__class__ is tuple)
1419+
verify(tuple(a).__class__ is tuple)
14201420
a = madtuple(())
14211421
verify(tuple(a) == ())
14221422
#XXX verify(tuple(a).__class__ is tuple)

Objects/abstract.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1235,7 +1235,11 @@ PySequence_Tuple(PyObject *v)
12351235
return null_error();
12361236

12371237
/* Special-case the common tuple and list cases, for efficiency. */
1238-
if (PyTuple_Check(v)) {
1238+
if (PyTuple_CheckExact(v)) {
1239+
/* Note that we can't know whether it's safe to return
1240+
a tuple *subclass* instance as-is, hence the restriction
1241+
to exact tuples here. In contrasts, lists always make
1242+
a copy, so there's need for exactness below. */
12391243
Py_INCREF(v);
12401244
return v;
12411245
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy