cpython: 9aa5424fd1df (original) (raw)

Mercurial > cpython

changeset 103378:9aa5424fd1df

Issue #24254: Drop cls.__definition_order__. [#24254]

Eric Snow ericsnowcurrently@gmail.com
date Thu, 08 Sep 2016 15:11:11 -0700
parents a06299a4b00c
children 4af9d196cd21
files Doc/library/inspect.rst Doc/library/types.rst Doc/reference/compound_stmts.rst Doc/reference/datamodel.rst Include/object.h Include/odictobject.h Lib/test/test_builtin.py Lib/test/test_metaclass.py Lib/test/test_pydoc.py Lib/test/test_sys.py Lib/test/test_types.py Lib/types.py Lib/typing.py Objects/odictobject.c Objects/typeobject.c Python/bltinmodule.c
diffstat 16 files changed, 193 insertions(+), 533 deletions(-)[+] [-] Doc/library/inspect.rst 367 Doc/library/types.rst 10 Doc/reference/compound_stmts.rst 12 Doc/reference/datamodel.rst 7 Include/object.h 2 Include/odictobject.h 4 Lib/test/test_builtin.py 192 Lib/test/test_metaclass.py 11 Lib/test/test_pydoc.py 8 Lib/test/test_sys.py 2 Lib/test/test_types.py 22 Lib/types.py 5 Lib/typing.py 1 Objects/odictobject.c 15 Objects/typeobject.c 66 Python/bltinmodule.c 2

line wrap: on

line diff

--- a/Doc/library/inspect.rst +++ b/Doc/library/inspect.rst @@ -34,190 +34,185 @@ provided as convenient choices for the s They also help you determine when you can expect to find the following special attributes: -+-----------+----------------------+---------------------------+ -| Type | Attribute | Description | -+===========+======================+===========================+ -| module | doc | documentation string | -+-----------+----------------------+---------------------------+ -| | file | filename (missing for | -| | | built-in modules) | -+-----------+----------------------+---------------------------+ -| class | doc | documentation string | -+-----------+----------------------+---------------------------+ -| | name | name with which this | -| | | class was defined | -+-----------+----------------------+---------------------------+ -| | qualname | qualified name | -+-----------+----------------------+---------------------------+ -| | module | name of module in which | -| | | this class was defined | -+-----------+----------------------+---------------------------+ -| | definition_order | the names of the class's | -| | | attributes, in the order | -| | | in which they were | -| | | defined (if known) | -+-----------+----------------------+---------------------------+ -| method | doc | documentation string | -+-----------+----------------------+---------------------------+ -| | name | name with which this | -| | | method was defined | -+-----------+----------------------+---------------------------+ -| | qualname | qualified name | -+-----------+----------------------+---------------------------+ -| | func | function object | -| | | containing implementation | -| | | of method | -+-----------+----------------------+---------------------------+ -| | self | instance to which this | -| | | method is bound, or | -| | | None | -+-----------+----------------------+---------------------------+ -| function | doc | documentation string | -+-----------+----------------------+---------------------------+ -| | name | name with which this | -| | | function was defined | -+-----------+----------------------+---------------------------+ -| | qualname | qualified name | -+-----------+----------------------+---------------------------+ -| | code | code object containing | -| | | compiled function | -| | | :term:bytecode | -+-----------+----------------------+---------------------------+ -| | defaults | tuple of any default | -| | | values for positional or | -| | | keyword parameters | -+-----------+----------------------+---------------------------+ -| | kwdefaults | mapping of any default | -| | | values for keyword-only | -| | | parameters | -+-----------+----------------------+---------------------------+ -| | globals | global namespace in which | -| | | this function was defined | -+-----------+----------------------+---------------------------+ -| | annotations | mapping of parameters | -| | | names to annotations; | -| | | "return" key is | -| | | reserved for return | -| | | annotations. | -+-----------+----------------------+---------------------------+ -| traceback | tb_frame | frame object at this | -| | | level | -+-----------+----------------------+---------------------------+ -| | tb_lasti | index of last attempted | -| | | instruction in bytecode | -+-----------+----------------------+---------------------------+ -| | tb_lineno | current line number in | -| | | Python source code | -+-----------+----------------------+---------------------------+ -| | tb_next | next inner traceback | -| | | object (called by this | -| | | level) | -+-----------+----------------------+---------------------------+ -| frame | f_back | next outer frame object | -| | | (this frame's caller) | -+-----------+----------------------+---------------------------+ -| | f_builtins | builtins namespace seen | -| | | by this frame | -+-----------+----------------------+---------------------------+ -| | f_code | code object being | -| | | executed in this frame | -+-----------+----------------------+---------------------------+ -| | f_globals | global namespace seen by | -| | | this frame | -+-----------+----------------------+---------------------------+ -| | f_lasti | index of last attempted | -| | | instruction in bytecode | -+-----------+----------------------+---------------------------+ -| | f_lineno | current line number in | -| | | Python source code | -+-----------+----------------------+---------------------------+ -| | f_locals | local namespace seen by | -| | | this frame | -+-----------+----------------------+---------------------------+ -| | f_restricted | 0 or 1 if frame is in | -| | | restricted execution mode | -+-----------+----------------------+---------------------------+ -| | f_trace | tracing function for this | -| | | frame, or None | -+-----------+----------------------+---------------------------+ -| code | co_argcount | number of arguments (not | -| | | including * or ** | -| | | args) | -+-----------+----------------------+---------------------------+ -| | co_code | string of raw compiled | -| | | bytecode | -+-----------+----------------------+---------------------------+ -| | co_consts | tuple of constants used | -| | | in the bytecode | -+-----------+----------------------+---------------------------+ -| | co_filename | name of file in which | -| | | this code object was | -| | | created | -+-----------+----------------------+---------------------------+ -| | co_firstlineno | number of first line in | -| | | Python source code | -+-----------+----------------------+---------------------------+ -| | co_flags | bitmap: 1=optimized | | -| | | 2=newlocals | 4=*arg | -| | | | 8=**arg | -+-----------+----------------------+---------------------------+ -| | co_lnotab | encoded mapping of line | -| | | numbers to bytecode | -| | | indices | -+-----------+----------------------+---------------------------+ -| | co_name | name with which this code | -| | | object was defined | -+-----------+----------------------+---------------------------+ -| | co_names | tuple of names of local | -| | | variables | -+-----------+----------------------+---------------------------+ -| | co_nlocals | number of local variables | -+-----------+----------------------+---------------------------+ -| | co_stacksize | virtual machine stack | -| | | space required | -+-----------+----------------------+---------------------------+ -| | co_varnames | tuple of names of | -| | | arguments and local | -| | | variables | -+-----------+----------------------+---------------------------+ -| generator | name | name | -+-----------+----------------------+---------------------------+ -| | qualname | qualified name | -+-----------+----------------------+---------------------------+ -| | gi_frame | frame | -+-----------+----------------------+---------------------------+ -| | gi_running | is the generator running? | -+-----------+----------------------+---------------------------+ -| | gi_code | code | -+-----------+----------------------+---------------------------+ -| | gi_yieldfrom | object being iterated by | -| | | yield from, or | -| | | None | -+-----------+----------------------+---------------------------+ -| coroutine | name | name | -+-----------+----------------------+---------------------------+ -| | qualname | qualified name | -+-----------+----------------------+---------------------------+ -| | cr_await | object being awaited on, | -| | | or None | -+-----------+----------------------+---------------------------+ -| | cr_frame | frame | -+-----------+----------------------+---------------------------+ -| | cr_running | is the coroutine running? | -+-----------+----------------------+---------------------------+ -| | cr_code | code | -+-----------+----------------------+---------------------------+ -| builtin | doc | documentation string | -+-----------+----------------------+---------------------------+ -| | name | original name of this | -| | | function or method | -+-----------+----------------------+---------------------------+ -| | qualname | qualified name | -+-----------+----------------------+---------------------------+ -| | self | instance to which a | -| | | method is bound, or | -| | | None | -+-----------+----------------------+---------------------------+ ++-----------+-----------------+---------------------------+ +| Type | Attribute | Description | ++===========+=================+===========================+ +| module | doc | documentation string | ++-----------+-----------------+---------------------------+ +| | file | filename (missing for | +| | | built-in modules) | ++-----------+-----------------+---------------------------+ +| class | doc | documentation string | ++-----------+-----------------+---------------------------+ +| | name | name with which this | +| | | class was defined | ++-----------+-----------------+---------------------------+ +| | qualname | qualified name | ++-----------+-----------------+---------------------------+ +| | module | name of module in which | +| | | this class was defined | ++-----------+-----------------+---------------------------+ +| method | doc | documentation string | ++-----------+-----------------+---------------------------+ +| | name | name with which this | +| | | method was defined | ++-----------+-----------------+---------------------------+ +| | qualname | qualified name | ++-----------+-----------------+---------------------------+ +| | func | function object | +| | | containing implementation | +| | | of method | ++-----------+-----------------+---------------------------+ +| | self | instance to which this | +| | | method is bound, or | +| | | None | ++-----------+-----------------+---------------------------+ +| function | doc | documentation string | ++-----------+-----------------+---------------------------+ +| | name | name with which this | +| | | function was defined | ++-----------+-----------------+---------------------------+ +| | qualname | qualified name | ++-----------+-----------------+---------------------------+ +| | code | code object containing | +| | | compiled function | +| | | :term:bytecode | ++-----------+-----------------+---------------------------+ +| | defaults | tuple of any default | +| | | values for positional or | +| | | keyword parameters | ++-----------+-----------------+---------------------------+ +| | kwdefaults | mapping of any default | +| | | values for keyword-only | +| | | parameters | ++-----------+-----------------+---------------------------+ +| | globals | global namespace in which | +| | | this function was defined | ++-----------+-----------------+---------------------------+ +| | annotations | mapping of parameters | +| | | names to annotations; | +| | | "return" key is | +| | | reserved for return | +| | | annotations. | ++-----------+-----------------+---------------------------+ +| traceback | tb_frame | frame object at this | +| | | level | ++-----------+-----------------+---------------------------+ +| | tb_lasti | index of last attempted | +| | | instruction in bytecode | ++-----------+-----------------+---------------------------+ +| | tb_lineno | current line number in | +| | | Python source code | ++-----------+-----------------+---------------------------+ +| | tb_next | next inner traceback | +| | | object (called by this | +| | | level) | ++-----------+-----------------+---------------------------+ +| frame | f_back | next outer frame object | +| | | (this frame's caller) | ++-----------+-----------------+---------------------------+ +| | f_builtins | builtins namespace seen | +| | | by this frame | ++-----------+-----------------+---------------------------+ +| | f_code | code object being | +| | | executed in this frame | ++-----------+-----------------+---------------------------+ +| | f_globals | global namespace seen by | +| | | this frame | ++-----------+-----------------+---------------------------+ +| | f_lasti | index of last attempted | +| | | instruction in bytecode | ++-----------+-----------------+---------------------------+ +| | f_lineno | current line number in | +| | | Python source code | ++-----------+-----------------+---------------------------+ +| | f_locals | local namespace seen by | +| | | this frame | ++-----------+-----------------+---------------------------+ +| | f_restricted | 0 or 1 if frame is in | +| | | restricted execution mode | ++-----------+-----------------+---------------------------+ +| | f_trace | tracing function for this | +| | | frame, or None | ++-----------+-----------------+---------------------------+ +| code | co_argcount | number of arguments (not | +| | | including * or ** | +| | | args) | ++-----------+-----------------+---------------------------+ +| | co_code | string of raw compiled | +| | | bytecode | ++-----------+-----------------+---------------------------+ +| | co_consts | tuple of constants used | +| | | in the bytecode | ++-----------+-----------------+---------------------------+ +| | co_filename | name of file in which | +| | | this code object was | +| | | created | ++-----------+-----------------+---------------------------+ +| | co_firstlineno | number of first line in | +| | | Python source code | ++-----------+-----------------+---------------------------+ +| | co_flags | bitmap: 1=optimized | | +| | | 2=newlocals | 4=*arg | +| | | | 8=**arg | ++-----------+-----------------+---------------------------+ +| | co_lnotab | encoded mapping of line | +| | | numbers to bytecode | +| | | indices | ++-----------+-----------------+---------------------------+ +| | co_name | name with which this code | +| | | object was defined | ++-----------+-----------------+---------------------------+ +| | co_names | tuple of names of local | +| | | variables | ++-----------+-----------------+---------------------------+ +| | co_nlocals | number of local variables | ++-----------+-----------------+---------------------------+ +| | co_stacksize | virtual machine stack | +| | | space required | ++-----------+-----------------+---------------------------+ +| | co_varnames | tuple of names of | +| | | arguments and local | +| | | variables | ++-----------+-----------------+---------------------------+ +| generator | name | name | ++-----------+-----------------+---------------------------+ +| | qualname | qualified name | ++-----------+-----------------+---------------------------+ +| | gi_frame | frame | ++-----------+-----------------+---------------------------+ +| | gi_running | is the generator running? | ++-----------+-----------------+---------------------------+ +| | gi_code | code | ++-----------+-----------------+---------------------------+ +| | gi_yieldfrom | object being iterated by | +| | | yield from, or | +| | | None | ++-----------+-----------------+---------------------------+ +| coroutine | name | name | ++-----------+-----------------+---------------------------+ +| | qualname | qualified name | ++-----------+-----------------+---------------------------+ +| | cr_await | object being awaited on, | +| | | or None | ++-----------+-----------------+---------------------------+ +| | cr_frame | frame | ++-----------+-----------------+---------------------------+ +| | cr_running | is the coroutine running? | ++-----------+-----------------+---------------------------+ +| | cr_code | code | ++-----------+-----------------+---------------------------+ +| builtin | doc | documentation string | ++-----------+-----------------+---------------------------+ +| | name | original name of this | +| | | function or method | ++-----------+-----------------+---------------------------+ +| | qualname | qualified name | ++-----------+-----------------+---------------------------+ +| | self | instance to which a | +| | | method is bound, or | +| | | None | ++-----------+-----------------+---------------------------+ .. versionchanged:: 3.5 @@ -226,10 +221,6 @@ attributes: The __name__ attribute of generators is now set from the function name, instead of the code name, and it can now be modified. -.. versionchanged:: 3.6 -

.. function:: getmembers(object[, predicate])

--- a/Doc/library/types.rst +++ b/Doc/library/types.rst @@ -53,19 +53,13 @@ Dynamic Type Creation in kwds argument with any 'metaclass' entry removed. If no kwds argument is passed in, this will be an empty dict.

- .. versionadded:: 3.3 .. versionchanged:: 3.6 The default value for the namespace element of the returned

.. seealso::

--- a/Doc/reference/compound_stmts.rst +++ b/Doc/reference/compound_stmts.rst @@ -634,15 +634,9 @@ dictionary. The class name is bound to namespace. The order in which attributes are defined in the class body is preserved -in the __definition_order__ attribute on the new class. If that order -is not known then the attribute is set to :const:None. The class body -may include a __definition_order__ attribute. In that case it is used -directly. The value must be a tuple of identifiers or None, otherwise -:exc:TypeError will be raised when the class statement is executed. - -.. versionchanged:: 3.6 -

Class creation can be customized heavily using :ref:metaclasses <metaclasses>.

--- a/Doc/reference/datamodel.rst +++ b/Doc/reference/datamodel.rst @@ -1752,13 +1752,6 @@ additional keyword arguments, if any, co If the metaclass has no __prepare__ attribute, then the class namespace is initialised as an empty ordered mapping. -.. impl-detail:: -

-.. versionchanged:: 3.6

.. seealso:: :pep:3115 - Metaclasses in Python 3000

--- a/Include/object.h +++ b/Include/object.h @@ -421,8 +421,6 @@ typedef struct _typeobject { destructor tp_finalize;

- #ifdef COUNT_ALLOCS /* these must be last and never explicitly initialized */ Py_ssize_t tp_allocs;

--- a/Include/odictobject.h +++ b/Include/odictobject.h @@ -28,10 +28,6 @@ PyAPI_FUNC(PyObject *) PyODict_New(void) PyAPI_FUNC(int) PyODict_SetItem(PyObject *od, PyObject *key, PyObject *item); PyAPI_FUNC(int) PyODict_DelItem(PyObject *od, PyObject *key); -#ifndef Py_LIMITED_API -PyAPI_FUNC(PyObject ) _PyODict_KeysAsTuple(PyObject od); -#endif - / wrappers around PyDict functions */ #define PyODict_GetItem(od, key) PyDict_GetItem((PyObject *)od, key) #define PyODict_GetItemWithError(od, key) [](#l6.13)

--- a/Lib/test/test_builtin.py +++ b/Lib/test/test_builtin.py @@ -16,10 +16,8 @@ import traceback import types import unittest import warnings -from collections import OrderedDict from operator import neg -from test.support import (TESTFN, unlink, run_unittest, check_warnings,

+from test.support import TESTFN, unlink, run_unittest, check_warnings from test.support.script_helper import assert_python_ok try: import pty, signal @@ -1780,194 +1778,6 @@ class TestType(unittest.TestCase): A.doc = doc self.assertEqual(A.doc, doc)

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

- def test_bad_args(self): with self.assertRaises(TypeError): type()

--- a/Lib/test/test_metaclass.py +++ b/Lib/test/test_metaclass.py @@ -180,7 +180,7 @@ Use a metaclass that doesn't derive from meta: C () ns: [('module', 'test.test_metaclass'), ('qualname', 'C'), ('a', 42), ('b', 24)] kw: []

Trace function introduces locals which causes various tests to fail.

if hasattr(sys, 'gettrace') and sys.gettrace():

--- a/Lib/test/test_pydoc.py +++ b/Lib/test/test_pydoc.py @@ -427,7 +427,6 @@ class PydocDocTest(unittest.TestCase): expected_html = expected_html_pattern % ( (mod_url, mod_file, doc_loc) + expected_html_data_docstrings)

@unittest.skipIf(sys.flags.optimize >= 2, @@ -474,18 +473,13 @@ class PydocDocTest(unittest.TestCase): def test_non_str_name(self): # issue14638 # Treat illegal (non-str) name like no name

def test_not_here(self): missing_module = "test.i_am_not_here"

--- a/Lib/test/test_sys.py +++ b/Lib/test/test_sys.py @@ -1085,7 +1085,7 @@ class SizeofTest(unittest.TestCase): check((1,2,3), vsize('') + 3*self.P) # type # static type: PyTypeObject

--- a/Lib/test/test_types.py +++ b/Lib/test/test_types.py @@ -825,28 +825,6 @@ class ClassCreationTests(unittest.TestCa self.assertEqual(C.y, 1) self.assertEqual(C.z, 2)

-

-

-

- # Many of the following tests are derived from test_descr.py def test_prepare_class(self): # Basic test of metaclass derivation

--- a/Lib/types.py +++ b/Lib/types.py @@ -25,11 +25,8 @@ CoroutineType = type(_c) _c.close() # Prevent ResourceWarning class _C:

--- a/Lib/typing.py +++ b/Lib/typing.py @@ -1301,7 +1301,6 @@ class _ProtocolMeta(GenericMeta): if (not attr.startswith('abc') and attr != 'abstractmethods' and attr != '_is_protocol' and

--- a/Objects/odictobject.c +++ b/Objects/odictobject.c @@ -1765,21 +1765,6 @@ PyODict_DelItem(PyObject *od, PyObject * return _PyDict_DelItem_KnownHash(od, key, hash); } -PyObject * -_PyODict_KeysAsTuple(PyObject *od) {

-} - /* -------------------------------------------

--- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -48,7 +48,6 @@ static size_t method_cache_collisions = _Py_IDENTIFIER(abstractmethods); _Py_IDENTIFIER(class); _Py_IDENTIFIER(delitem); -_Py_IDENTIFIER(definition_order); _Py_IDENTIFIER(dict); _Py_IDENTIFIER(doc); _Py_IDENTIFIER(getattribute); @@ -490,23 +489,6 @@ type_set_module(PyTypeObject *type, PyOb } static PyObject * -type_deforder(PyTypeObject *type, void *context) -{

-} - -static int -type_set_deforder(PyTypeObject *type, PyObject *value, void *context) -{

-} - -static PyObject * type_abstractmethods(PyTypeObject *type, void *context) { PyObject *mod = NULL; @@ -852,8 +834,6 @@ static PyGetSetDef type_getsets[] = { {"qualname", (getter)type_qualname, (setter)type_set_qualname, NULL}, {"bases", (getter)type_get_bases, (setter)type_set_bases, NULL}, {"module", (getter)type_module, (setter)type_set_module, NULL},

@@ -2580,48 +2559,6 @@ type_new(PyTypeObject *metatype, PyObjec if (qualname != NULL && PyDict_DelItem(dict, PyId___qualname__.object) < 0) goto error;

-

-

-

-

- /* Set tp_doc to a copy of dict['doc'], if the latter is there and is a string. The doc accessor will first look for tp_doc; if that fails, it will still look into dict. @@ -3136,7 +3073,6 @@ type_dealloc(PyTypeObject *type) Py_XDECREF(type->tp_mro); Py_XDECREF(type->tp_cache); Py_XDECREF(type->tp_subclasses);

} /*

--- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -147,7 +147,7 @@ builtin___build_class__(PyObject *self, if (prep == NULL) { if (PyErr_ExceptionMatches(PyExc_AttributeError)) { PyErr_Clear();