GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — bpo-41171: Added method "PyMetaType_FromSpec" to allow for specifying the metaclass for the type. by WildCard65 · Pull Request #21238 · python/cpython

bpo-41171: Added method "PyMetaType_FromSpec" to allow for specifying the metaclass for the type. #21238

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
WildCard65 wants to merge 7 commits into python:main from WildCard65:bpo-41171

Uh oh!

There was an error while loading. Please reload this page.

Closed

bpo-41171: Added method "PyMetaType_FromSpec" to allow for specifying the metaclass for the type. #21238

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
7 commits
Select commit Hold shift + click to select a range
5e73355
bpo-41171: Added companion "FromSpec" methods prefixed with "PyMetaTy…
WildCard65 Jun 30, 2020
745387c
Removed 'PyMetaType_FromSpecAndBases'.
WildCard65 Jun 30, 2020
e2cde2c
📜🤖 Added by blurb_it.
blurb-it[bot] Jun 30, 2020
faa247a
Fixed documentation error of 'PyType_FromSpecWithBases'
WildCard65 Jun 30, 2020
9089911
Fixed dangling function export.
WildCard65 Jun 30, 2020
1ea9a54
Renamed "PyMetaType_FromModuleAndSpec" to "PyMetaType_FromSpec".
WildCard65 Jun 30, 2020
df908fe
Updated NEWS entry to reflect changes.
WildCard65 Jun 30, 2020
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

20 changes: 15 additions & 5 deletions 20 Doc/c-api/type.rst
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,13 @@ The following functions and structs are used to create

.. c:function:: PyObject* PyType_FromModuleAndSpec(PyObject *module, PyType_Spec *spec, PyObject *bases)

Creates and returns a heap type object from the *spec*
Equivalent to ``PyMetaType_FromSpec(module, &PyType_Type, spec, bases)``.

.. versionadded:: 3.9

.. c:function:: PyObject* PyMetaType_FromSpec(PyObject *module, PyTypeObject *meta_type, PyType_Spec *spec, PyObject *bases)

Creates and returns a heap type object from the *spec* whose's metaclass is *meta_type*
(:const:`Py_TPFLAGS_HEAPTYPE`).

If *bases* is a tuple, the created heap type contains all types contained
Expand All @@ -155,19 +161,23 @@ The following functions and structs are used to create
If not ``NULL``, the module is associated with the new type and can later be
retreived with :c:func:`PyType_GetModule`.

This function calls :c:func:`PyType_Ready` on the new type.
This function calls :c:func:`PyType_Ready` on the new type.'

.. versionadded:: 3.9
.. note::

This method DOES NOT invoke ``PyTypeObject.tp_new`` on 'meta_type'.

.. versionadded:: 3.10

.. c:function:: PyObject* PyType_FromSpecWithBases(PyType_Spec *spec, PyObject *bases)

Equivalent to ``PyType_FromModuleAndSpec(NULL, spec, bases)``.
Equivalent to ``PyMetaType_FromSpec(NULL, &PyType_Type, spec, bases)``.

.. versionadded:: 3.3

.. c:function:: PyObject* PyType_FromSpec(PyType_Spec *spec)

Equivalent to ``PyType_FromSpecWithBases(spec, NULL)``.
Equivalent to ``PyMetaType_FromSpec(NULL, &PyType_Type, spec, NULL)``.

.. c:type:: PyType_Spec

Expand Down
7 changes: 4 additions & 3 deletions 7 Include/object.h
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -225,15 +225,16 @@ typedef struct{
PyType_Slot *slots; /* terminated by slot==0. */
} PyType_Spec;

PyAPI_FUNC(PyObject*) PyType_FromSpec(PyType_Spec*);
#define PyType_FromSpec(spec) PyMetaType_FromSpec(NULL, &PyType_Type, spec, NULL)
PyAPI_FUNC(PyObject*) PyMetaType_FromSpec(PyObject*, PyTypeObject*, PyType_Spec*, PyObject*);
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000
PyAPI_FUNC(PyObject*) PyType_FromSpecWithBases(PyType_Spec*, PyObject*);
#define PyType_FromSpecWithBases(spec, bases) PyMetaType_FromSpec(NULL, &PyType_Type, spec, bases)
#endif
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03040000
PyAPI_FUNC(void*) PyType_GetSlot(PyTypeObject*, int);
#endif
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03090000
PyAPI_FUNC(PyObject*) PyType_FromModuleAndSpec(PyObject *, PyType_Spec *, PyObject *);
#define PyType_FromModuleAndSpec(module, spec, bases) PyMetaType_FromSpec(module, &PyType_Type, spec, bases)
PyAPI_FUNC(PyObject *) PyType_GetModule(struct _typeobject *);
PyAPI_FUNC(void *) PyType_GetModuleState(struct _typeobject *);
#endif
Expand Down
1 change: 1 addition & 0 deletions 1 Misc/NEWS.d/next/C API/2020-06-30-16-31-15.bpo-41171.wFnoOM.rst
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added method "PyMetaType_FromSpec" to allow for specifying the metaclass for the type.
19 changes: 6 additions & 13 deletions 19 Objects/typeobject.c
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -2880,14 +2880,13 @@ static const short slotoffsets[] = {
};

PyObject *
PyType_FromSpecWithBases(PyType_Spec *spec, PyObject *bases)
PyMetaType_FromSpec(PyObject *module, PyTypeObject *meta_type, PyType_Spec *spec, PyObject *bases)
{
return PyType_FromModuleAndSpec(NULL, spec, bases);
}
if (meta_type == NULL) {
PyErr_BadArgument();
return NULL;
}

PyObject *
PyType_FromModuleAndSpec(PyObject *module, PyType_Spec *spec, PyObject *bases)
{
PyHeapTypeObject *res;
PyObject *modname;
PyTypeObject *type, *base;
Expand Down Expand Up @@ -2924,7 +2923,7 @@ PyType_FromModuleAndSpec(PyObject *module, PyType_Spec *spec, PyObject *bases)
}
}

res = (PyHeapTypeObject*)PyType_GenericAlloc(&PyType_Type, nmembers);
res = (PyHeapTypeObject*)PyType_GenericAlloc(meta_type, nmembers);
if (res == NULL)
return NULL;
res_start = (char*)res;
Expand Down Expand Up @@ -3098,12 +3097,6 @@ PyType_FromModuleAndSpec(PyObject *module, PyType_Spec *spec, PyObject *bases)
return NULL;
}

PyObject *
PyType_FromSpec(PyType_Spec *spec)
{
return PyType_FromSpecWithBases(spec, NULL);
}

void *
PyType_GetSlot(PyTypeObject *type, int slot)
{
Expand Down
3 changes: 1 addition & 2 deletions 3 PC/python3dll.c
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -541,8 +541,7 @@ EXPORT_FUNC(PyTuple_Pack)
EXPORT_FUNC(PyTuple_SetItem)
EXPORT_FUNC(PyTuple_Size)
EXPORT_FUNC(PyType_ClearCache)
EXPORT_FUNC(PyType_FromSpec)
EXPORT_FUNC(PyType_FromSpecWithBases)
EXPORT_FUNC(PyMetaType_FromSpec)
EXPORT_FUNC(PyType_GenericAlloc)
EXPORT_FUNC(PyType_GenericNew)
EXPORT_FUNC(PyType_GetFlags)
Expand Down
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.