Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit aa6c1d2

Browse files
committed
Issue #13575: there is only one class type.
1 parent 9d57481 commit aa6c1d2

8 files changed

Lines changed: 25 additions & 81 deletions

File tree

Doc/howto/descriptor.rst

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ continuing through the base classes of ``type(a)`` excluding metaclasses. If the
3636
looked-up value is an object defining one of the descriptor methods, then Python
3737
may override the default behavior and invoke the descriptor method instead.
3838
Where this occurs in the precedence chain depends on which descriptor methods
39-
were defined. Note that descriptors are only invoked for new style objects or
40-
classes (a class is new style if it inherits from :class:`object` or
41-
:class:`type`).
39+
were defined.
4240

4341
Descriptors are a powerful, general purpose protocol. They are the mechanism
4442
behind properties, methods, static methods, class methods, and :func:`super()`.
@@ -89,8 +87,6 @@ of ``obj``. If ``d`` defines the method :meth:`__get__`, then ``d.__get__(obj)`
8987
is invoked according to the precedence rules listed below.
9088

9189
The details of invocation depend on whether ``obj`` is an object or a class.
92-
Either way, descriptors only work for new style objects and classes. A class is
93-
new style if it is a subclass of :class:`object`.
9490

9591
For objects, the machinery is in :meth:`object.__getattribute__` which
9692
transforms ``b.x`` into ``type(b).__dict__['x'].__get__(b, type(b))``. The
@@ -115,7 +111,6 @@ The important points to remember are:
115111

116112
* descriptors are invoked by the :meth:`__getattribute__` method
117113
* overriding :meth:`__getattribute__` prevents automatic descriptor calls
118-
* :meth:`__getattribute__` is only available with new style classes and objects
119114
* :meth:`object.__getattribute__` and :meth:`type.__getattribute__` make
120115
different calls to :meth:`__get__`.
121116
* data descriptors always override instance dictionaries.
@@ -128,10 +123,7 @@ and then returns ``A.__dict__['m'].__get__(obj, A)``. If not a descriptor,
128123
``m`` is returned unchanged. If not in the dictionary, ``m`` reverts to a
129124
search using :meth:`object.__getattribute__`.
130125

131-
Note, in Python 2.2, ``super(B, obj).m()`` would only invoke :meth:`__get__` if
132-
``m`` was a data descriptor. In Python 2.3, non-data descriptors also get
133-
invoked unless an old-style class is involved. The implementation details are
134-
in :c:func:`super_getattro()` in
126+
The implementation details are in :c:func:`super_getattro()` in
135127
`Objects/typeobject.c <http://svn.python.org/view/python/trunk/Objects/typeobject.c?view=markup>`_
136128
and a pure Python equivalent can be found in `Guido's Tutorial`_.
137129

Lib/pickle.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ def save_reduce(self, func, args, state=None,
375375
# allowing protocol 0 and 1 to work normally. For this to
376376
# work, the function returned by __reduce__ should be
377377
# called __newobj__, and its first argument should be a
378-
# new-style class. The implementation for __newobj__
378+
# class. The implementation for __newobj__
379379
# should be as follows, although pickle has no way to
380380
# verify this:
381381
#

Lib/pickletools.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1639,6 +1639,8 @@ def __init__(self, name, code, arg,
16391639
is pushed on the stack.
16401640
16411641
NOTE: checks for __safe_for_unpickling__ went away in Python 2.3.
1642+
NOTE: the distinction between old-style and new-style classes does
1643+
not make sense in Python 3.
16421644
"""),
16431645

16441646
I(name='OBJ',

Modules/gc_weakref.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ have been called before resurrection). At best (and this has been an
1515
historically common bug), tp_clear empties an instance's __dict__, and
1616
"impossible" AttributeErrors result. At worst, tp_clear leaves behind an
1717
insane object at the C level, and segfaults result (historically, most
18-
often by setting a new-style class's mro pointer to NULL, after which
19-
attribute lookups performed by the class can segfault).
18+
often by setting a class's mro pointer to NULL, after which attribute
19+
lookups performed by the class can segfault).
2020

2121
OTOH, it's OK to run Python-level code that can't access unreachable
2222
objects, and sometimes that's necessary. The chief example is the callback
@@ -119,7 +119,7 @@ isn't easy to stumble into by accident while Python is running, and, indeed,
119119
it took quite a while to dream up failing test cases. Zope3 saw segfaults
120120
during shutdown, during the second call of gc in Py_Finalize, after most
121121
modules had been torn down. That creates many trash cycles (esp. those
122-
involving new-style classes), making the problem much more likely. Once you
122+
involving classes), making the problem much more likely. Once you
123123
know what's required to provoke the problem, though, it's easy to create
124124
tests that segfault before shutdown.
125125

Objects/typeobject.c

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,13 @@ PyType_Modified(PyTypeObject *type)
100100
static void
101101
type_mro_modified(PyTypeObject *type, PyObject *bases) {
102102
/*
103-
Check that all base classes or elements of the mro of type are
103+
Check that all base classes or elements of the MRO of type are
104104
able to be cached. This function is called after the base
105105
classes or mro of the type are altered.
106106
107107
Unset HAVE_VERSION_TAG and VALID_VERSION_TAG if the type
108-
inherits from an old-style class, either directly or if it
109-
appears in the MRO of a new-style class. No support either for
110-
custom MROs that include types that are not officially super
111-
types.
108+
has a custom MRO that includes a type which is not officially
109+
super type.
112110
113111
Called from mro_internal, which will subsequently be called on
114112
each subclass when their mro is recursively updated.
@@ -124,11 +122,7 @@ type_mro_modified(PyTypeObject *type, PyObject *bases) {
124122
PyObject *b = PyTuple_GET_ITEM(bases, i);
125123
PyTypeObject *cls;
126124

127-
if (!PyType_Check(b) ) {
128-
clear = 1;
129-
break;
130-
}
131-
125+
assert(PyType_Check(b));
132126
cls = (PyTypeObject *)b;
133127

134128
if (!PyType_HasFeature(cls, Py_TPFLAGS_HAVE_VERSION_TAG) ||
@@ -488,7 +482,7 @@ type_set_bases(PyTypeObject *type, PyObject *value, void *context)
488482
if (!PyType_Check(ob)) {
489483
PyErr_Format(
490484
PyExc_TypeError,
491-
"%s.__bases__ must be tuple of old- or new-style classes, not '%s'",
485+
"%s.__bases__ must be tuple of classes, not '%s'",
492486
type->tp_name, Py_TYPE(ob)->tp_name);
493487
return -1;
494488
}
@@ -1619,7 +1613,7 @@ mro_internal(PyTypeObject *type)
16191613
type->tp_mro = tuple;
16201614

16211615
type_mro_modified(type, type->tp_mro);
1622-
/* corner case: the old-style super class might have been hidden
1616+
/* corner case: the super class might have been hidden
16231617
from the custom MRO */
16241618
type_mro_modified(type, type->tp_bases);
16251619

@@ -1676,9 +1670,8 @@ best_base(PyObject *bases)
16761670
return NULL;
16771671
}
16781672
}
1679-
if (base == NULL)
1680-
PyErr_SetString(PyExc_TypeError,
1681-
"a new-style class can't have only classic bases");
1673+
assert (base != NULL);
1674+
16821675
return base;
16831676
}
16841677

@@ -3196,7 +3189,7 @@ object_set_class(PyObject *self, PyObject *value, void *closure)
31963189
}
31973190
if (!PyType_Check(value)) {
31983191
PyErr_Format(PyExc_TypeError,
3199-
"__class__ must be set to new-style class, not '%s' object",
3192+
"__class__ must be set to a class, not '%s' object",
32003193
Py_TYPE(value)->tp_name);
32013194
return -1;
32023195
}
@@ -3811,8 +3804,8 @@ inherit_special(PyTypeObject *type, PyTypeObject *base)
38113804
that the extension type's own factory function ensures).
38123805
Heap types, of course, are under our control, so they do
38133806
inherit tp_new; static extension types that specify some
3814-
other built-in type as the default are considered
3815-
new-style-aware so they also inherit object.__new__. */
3807+
other built-in type as the default also
3808+
inherit object.__new__. */
38163809
if (base != &PyBaseObject_Type ||
38173810
(type->tp_flags & Py_TPFLAGS_HEAPTYPE)) {
38183811
if (type->tp_new == NULL)
@@ -6352,7 +6345,7 @@ supercheck(PyTypeObject *type, PyObject *obj)
63526345
{
63536346
/* Check that a super() call makes sense. Return a type object.
63546347
6355-
obj can be a new-style class, or an instance of one:
6348+
obj can be a class, or an instance of one:
63566349
63576350
- If it is a class, it must be a subclass of 'type'. This case is
63586351
used for class methods; the return value is obj.

Python/errors.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ PyErr_NewException(const char *name, PyObject *base, PyObject *dict)
665665
if (bases == NULL)
666666
goto failure;
667667
}
668-
/* Create a real new-style class. */
668+
/* Create a real class. */
669669
result = PyObject_CallFunction((PyObject *)&PyType_Type, "sOO",
670670
dot+1, bases, dict);
671671
failure:

Python/pythonrun.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ Py_Finalize(void)
474474
flush_std_files();
475475

476476
/* Collect final garbage. This disposes of cycles created by
477-
* new-style class definitions, for example.
477+
* class definitions, for example.
478478
* XXX This is disabled because it caused too many problems. If
479479
* XXX a __del__ or weakref callback triggers here, Python code has
480480
* XXX a hard time running, because even the sys module has been
@@ -1348,11 +1348,6 @@ parse_syntax_error(PyObject *err, PyObject **message, const char **filename,
13481348
_Py_IDENTIFIER(offset);
13491349
_Py_IDENTIFIER(text);
13501350

1351-
/* old style errors */
1352-
if (PyTuple_Check(err))
1353-
return PyArg_ParseTuple(err, "O(ziiz)", message, filename,
1354-
lineno, offset, text);
1355-
13561351
/* new style errors. `err' is an instance */
13571352

13581353
if (! (v = _PyObject_GetAttrId(err, &PyId_msg)))

Tools/gdb/libpython.py

Lines changed: 3 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ def __repr__(self):
402402

403403

404404
def _write_instance_repr(out, visited, name, pyop_attrdict, address):
405-
'''Shared code for use by old-style and new-style classes:
405+
'''Shared code for use by all classes:
406406
write a representation to file-like object "out"'''
407407
out.write('<')
408408
out.write(name)
@@ -481,7 +481,7 @@ def get_attr_dict(self):
481481

482482
def proxyval(self, visited):
483483
'''
484-
Support for new-style classes.
484+
Support for classes.
485485
486486
Currently we just locate the dictionary using a transliteration to
487487
python of _PyObject_GetDictPtr, ignoring descriptors
@@ -498,7 +498,7 @@ def proxyval(self, visited):
498498
attr_dict = {}
499499
tp_name = self.safe_tp_name()
500500

501-
# New-style class:
501+
# Class:
502502
return InstanceProxy(tp_name, attr_dict, long(self._gdbval))
503503

504504
def write_repr(self, out, visited):
@@ -670,44 +670,6 @@ def write_repr(self, out, visited):
670670
pyop_value.write_repr(out, visited)
671671
out.write('}')
672672

673-
class PyInstanceObjectPtr(PyObjectPtr):
674-
_typename = 'PyInstanceObject'
675-
676-
def proxyval(self, visited):
677-
# Guard against infinite loops:
678-
if self.as_address() in visited:
679-
return ProxyAlreadyVisited('<...>')
680-
visited.add(self.as_address())
681-
682-
# Get name of class:
683-
in_class = self.pyop_field('in_class')
684-
cl_name = in_class.pyop_field('cl_name').proxyval(visited)
685-
686-
# Get dictionary of instance attributes:
687-
in_dict = self.pyop_field('in_dict').proxyval(visited)
688-
689-
# Old-style class:
690-
return InstanceProxy(cl_name, in_dict, long(self._gdbval))
691-
692-
def write_repr(self, out, visited):
693-
# Guard against infinite loops:
694-
if self.as_address() in visited:
695-
out.write('<...>')
696-
return
697-
visited.add(self.as_address())
698-
699-
# Old-style class:
700-
701-
# Get name of class:
702-
in_class = self.pyop_field('in_class')
703-
cl_name = in_class.pyop_field('cl_name').proxyval(visited)
704-
705-
# Get dictionary of instance attributes:
706-
pyop_in_dict = self.pyop_field('in_dict')
707-
708-
_write_instance_repr(out, visited,
709-
cl_name, pyop_in_dict, self.as_address())
710-
711673
class PyListObjectPtr(PyObjectPtr):
712674
_typename = 'PyListObject'
713675

0 commit comments

Comments
 (0)