From 67042fcbe412a66423bfc1c3f848094ccf0efbb3 Mon Sep 17 00:00:00 2001 From: ananthan-123 Date: Wed, 19 Feb 2020 16:38:21 +0530 Subject: [PATCH 01/12] language reference should specify restrictions on class namespace --- Doc/reference/datamodel.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst index 9520f824287f6b..8a1a7d139eb891 100644 --- a/Doc/reference/datamodel.rst +++ b/Doc/reference/datamodel.rst @@ -1933,7 +1933,6 @@ base classes. The most derived metaclass is one which is a subtype of *all* of these candidate metaclasses. If none of the candidate metaclasses meets that criterion, then the class definition will fail with ``TypeError``. - .. _prepare: Preparing the class namespace @@ -1946,10 +1945,11 @@ Once the appropriate metaclass has been identified, then the class namespace is prepared. If the metaclass has a ``__prepare__`` attribute, it is called as ``namespace = metaclass.__prepare__(name, bases, **kwds)`` (where the additional keyword arguments, if any, come from the class definition). The -``__prepare__`` method should be implemented as a :func:`classmethod`. ++namespace returned by ``__prepare__`` is passed in to ``__new__``, but when ++the final class object is created the namespace is copied into a new ``dict``. If the metaclass has no ``__prepare__`` attribute, then the class namespace -is initialised as an empty ordered mapping. + is initialised as an empty :func:`dict` instance. .. seealso:: From 3cc613cc392f68450838b661115222f2fb657f06 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Wed, 19 Feb 2020 11:13:48 +0000 Subject: [PATCH 02/12] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20b?= =?UTF-8?q?lurb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Documentation/2020-02-19-11-13-47.bpo-17422.g7_9zz.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Documentation/2020-02-19-11-13-47.bpo-17422.g7_9zz.rst diff --git a/Misc/NEWS.d/next/Documentation/2020-02-19-11-13-47.bpo-17422.g7_9zz.rst b/Misc/NEWS.d/next/Documentation/2020-02-19-11-13-47.bpo-17422.g7_9zz.rst new file mode 100644 index 00000000000000..ef2b0a861b339b --- /dev/null +++ b/Misc/NEWS.d/next/Documentation/2020-02-19-11-13-47.bpo-17422.g7_9zz.rst @@ -0,0 +1 @@ +Language reference should specify restrictions on :class:"namespace". \ No newline at end of file From 5344bd5f9939029114d9e63dbb8581ad144ca7d8 Mon Sep 17 00:00:00 2001 From: ananthan-123 Date: Wed, 19 Feb 2020 19:12:22 +0530 Subject: [PATCH 03/12] Update 2020-02-19-11-13-47.bpo-17422.g7_9zz.rst --- .../next/Documentation/2020-02-19-11-13-47.bpo-17422.g7_9zz.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Documentation/2020-02-19-11-13-47.bpo-17422.g7_9zz.rst b/Misc/NEWS.d/next/Documentation/2020-02-19-11-13-47.bpo-17422.g7_9zz.rst index ef2b0a861b339b..c38081d5536dbd 100644 --- a/Misc/NEWS.d/next/Documentation/2020-02-19-11-13-47.bpo-17422.g7_9zz.rst +++ b/Misc/NEWS.d/next/Documentation/2020-02-19-11-13-47.bpo-17422.g7_9zz.rst @@ -1 +1 @@ -Language reference should specify restrictions on :class:"namespace". \ No newline at end of file +Language reference should specify restrictions on class namespace. From ce1211d91493d77d3532efe8771de877636d6510 Mon Sep 17 00:00:00 2001 From: ananthan-123 Date: Fri, 21 Feb 2020 21:37:08 +0530 Subject: [PATCH 04/12] Update datamodel.rst --- Doc/reference/datamodel.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst index 8a1a7d139eb891..1c99eac24aa958 100644 --- a/Doc/reference/datamodel.rst +++ b/Doc/reference/datamodel.rst @@ -1932,7 +1932,6 @@ metaclass (if any) and the metaclasses (i.e. ``type(cls)``) of all specified base classes. The most derived metaclass is one which is a subtype of *all* of these candidate metaclasses. If none of the candidate metaclasses meets that criterion, then the class definition will fail with ``TypeError``. - .. _prepare: Preparing the class namespace From 50bf96c44e4523e44feda92ab9591d664932fcf3 Mon Sep 17 00:00:00 2001 From: ananthan-123 Date: Fri, 21 Feb 2020 21:38:43 +0530 Subject: [PATCH 05/12] Update datamodel.rst --- Doc/reference/datamodel.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst index 1c99eac24aa958..4e72f355499d92 100644 --- a/Doc/reference/datamodel.rst +++ b/Doc/reference/datamodel.rst @@ -1932,8 +1932,8 @@ metaclass (if any) and the metaclasses (i.e. ``type(cls)``) of all specified base classes. The most derived metaclass is one which is a subtype of *all* of these candidate metaclasses. If none of the candidate metaclasses meets that criterion, then the class definition will fail with ``TypeError``. -.. _prepare: +.. _prepare: Preparing the class namespace ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ From fe0e189d4a022ec442dedcfe647191f9d18545b0 Mon Sep 17 00:00:00 2001 From: ananthan-123 Date: Fri, 21 Feb 2020 21:39:34 +0530 Subject: [PATCH 06/12] Update datamodel.rst --- Doc/reference/datamodel.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst index 4e72f355499d92..4452a3a9e57b18 100644 --- a/Doc/reference/datamodel.rst +++ b/Doc/reference/datamodel.rst @@ -1932,7 +1932,6 @@ metaclass (if any) and the metaclasses (i.e. ``type(cls)``) of all specified base classes. The most derived metaclass is one which is a subtype of *all* of these candidate metaclasses. If none of the candidate metaclasses meets that criterion, then the class definition will fail with ``TypeError``. - .. _prepare: Preparing the class namespace ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ From 0cbefbd41d651f7c9cbafe88b3ce3e715162c961 Mon Sep 17 00:00:00 2001 From: ananthan-123 Date: Fri, 21 Feb 2020 21:40:47 +0530 Subject: [PATCH 07/12] Update Doc/reference/datamodel.rst Co-Authored-By: Brandt Bucher --- Doc/reference/datamodel.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst index 4452a3a9e57b18..a41db10922e128 100644 --- a/Doc/reference/datamodel.rst +++ b/Doc/reference/datamodel.rst @@ -1947,7 +1947,7 @@ additional keyword arguments, if any, come from the class definition). The +the final class object is created the namespace is copied into a new ``dict``. If the metaclass has no ``__prepare__`` attribute, then the class namespace - is initialised as an empty :func:`dict` instance. +is initialised as an empty :func:`dict`. .. seealso:: From 8ff956a9268f8e718fdce58c10310e38c18db0e2 Mon Sep 17 00:00:00 2001 From: ananthan-123 Date: Fri, 21 Feb 2020 21:41:14 +0530 Subject: [PATCH 08/12] Update Misc/NEWS.d/next/Documentation/2020-02-19-11-13-47.bpo-17422.g7_9zz.rst Co-Authored-By: Brandt Bucher --- .../next/Documentation/2020-02-19-11-13-47.bpo-17422.g7_9zz.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Documentation/2020-02-19-11-13-47.bpo-17422.g7_9zz.rst b/Misc/NEWS.d/next/Documentation/2020-02-19-11-13-47.bpo-17422.g7_9zz.rst index c38081d5536dbd..e0f01432e686de 100644 --- a/Misc/NEWS.d/next/Documentation/2020-02-19-11-13-47.bpo-17422.g7_9zz.rst +++ b/Misc/NEWS.d/next/Documentation/2020-02-19-11-13-47.bpo-17422.g7_9zz.rst @@ -1 +1 @@ -Language reference should specify restrictions on class namespace. +The language reference now specifies restrictions on class namespaces. From 1d37fb23add77e6c3d79de3f5007990ec9721f1d Mon Sep 17 00:00:00 2001 From: ananthan-123 Date: Fri, 21 Feb 2020 21:49:15 +0530 Subject: [PATCH 09/12] Update datamodel.rst --- Doc/reference/datamodel.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst index a41db10922e128..65bab2a70281e7 100644 --- a/Doc/reference/datamodel.rst +++ b/Doc/reference/datamodel.rst @@ -1932,7 +1932,10 @@ metaclass (if any) and the metaclasses (i.e. ``type(cls)``) of all specified base classes. The most derived metaclass is one which is a subtype of *all* of these candidate metaclasses. If none of the candidate metaclasses meets that criterion, then the class definition will fail with ``TypeError``. + + .. _prepare: + Preparing the class namespace ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -1945,6 +1948,7 @@ as ``namespace = metaclass.__prepare__(name, bases, **kwds)`` (where the additional keyword arguments, if any, come from the class definition). The +namespace returned by ``__prepare__`` is passed in to ``__new__``, but when +the final class object is created the namespace is copied into a new ``dict``. +The ``__prepare__`` method should be implemented as a :func:`classmethod`. If the metaclass has no ``__prepare__`` attribute, then the class namespace is initialised as an empty :func:`dict`. From c0d625172dfa57f96f9ee75c6dd902710fd4373f Mon Sep 17 00:00:00 2001 From: ananthan-123 Date: Fri, 21 Feb 2020 21:52:15 +0530 Subject: [PATCH 10/12] Update datamodel.rst --- Doc/reference/datamodel.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst index 65bab2a70281e7..6183be40dc721e 100644 --- a/Doc/reference/datamodel.rst +++ b/Doc/reference/datamodel.rst @@ -1946,8 +1946,8 @@ Once the appropriate metaclass has been identified, then the class namespace is prepared. If the metaclass has a ``__prepare__`` attribute, it is called as ``namespace = metaclass.__prepare__(name, bases, **kwds)`` (where the additional keyword arguments, if any, come from the class definition). The -+namespace returned by ``__prepare__`` is passed in to ``__new__``, but when -+the final class object is created the namespace is copied into a new ``dict``. +namespace returned by ``__prepare__`` is passed in to ``__new__``, but when +the final class object is created the namespace is copied into a new ``dict``. The ``__prepare__`` method should be implemented as a :func:`classmethod`. If the metaclass has no ``__prepare__`` attribute, then the class namespace From 9823caa899982069581c12918556177e19d5dcf6 Mon Sep 17 00:00:00 2001 From: ananthan-123 Date: Fri, 21 Feb 2020 21:55:51 +0530 Subject: [PATCH 11/12] Update datamodel.rst --- Doc/reference/datamodel.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst index 6183be40dc721e..5b3b669c5eb91f 100644 --- a/Doc/reference/datamodel.rst +++ b/Doc/reference/datamodel.rst @@ -1946,9 +1946,9 @@ Once the appropriate metaclass has been identified, then the class namespace is prepared. If the metaclass has a ``__prepare__`` attribute, it is called as ``namespace = metaclass.__prepare__(name, bases, **kwds)`` (where the additional keyword arguments, if any, come from the class definition). The +``__prepare__`` method should be implemented as a :func:`classmethod`. The namespace returned by ``__prepare__`` is passed in to ``__new__``, but when the final class object is created the namespace is copied into a new ``dict``. -The ``__prepare__`` method should be implemented as a :func:`classmethod`. If the metaclass has no ``__prepare__`` attribute, then the class namespace is initialised as an empty :func:`dict`. From 1c648cdfb232025bdc8f18c260ff0255f6ffe125 Mon Sep 17 00:00:00 2001 From: ananthan-123 Date: Sat, 22 Feb 2020 09:01:10 +0530 Subject: [PATCH 12/12] Update Misc/NEWS.d/next/Documentation/2020-02-19-11-13-47.bpo-17422.g7_9zz.rst Co-Authored-By: Brandt Bucher --- .../next/Documentation/2020-02-19-11-13-47.bpo-17422.g7_9zz.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Documentation/2020-02-19-11-13-47.bpo-17422.g7_9zz.rst b/Misc/NEWS.d/next/Documentation/2020-02-19-11-13-47.bpo-17422.g7_9zz.rst index e0f01432e686de..f071d286176aee 100644 --- a/Misc/NEWS.d/next/Documentation/2020-02-19-11-13-47.bpo-17422.g7_9zz.rst +++ b/Misc/NEWS.d/next/Documentation/2020-02-19-11-13-47.bpo-17422.g7_9zz.rst @@ -1 +1 @@ -The language reference now specifies restrictions on class namespaces. +The language reference now specifies restrictions on class namespaces. Adapted from a patch by Ethan Furman.