File tree Expand file tree Collapse file tree 4 files changed +37
-12
lines changed
Misc/NEWS.d/next/Core and Builtins Expand file tree Collapse file tree 4 files changed +37
-12
lines changed Original file line number Diff line number Diff line change @@ -62,12 +62,15 @@ the definition of all other Python objects.
6262 See documentation of :c:type: `PyVarObject ` above.
6363
6464
65- .. c :macro :: Py_TYPE(o)
65+ .. c :function :: PyTypeObject* Py_TYPE (const PyObject * o)
6666
67- This macro is used to access the :attr: `ob_type ` member of a Python object.
68- It expands to::
67+ Get the type of the Python object *o *.
68+
69+ Return a borrowed reference.
6970
70- (((PyObject*)(o))->ob_type)
71+ .. versionchanged :: 3.10
72+ :c:func: `Py_TYPE() ` is changed to the inline static function.
73+ Use :c:func: `Py_SET_TYPE() ` to set an object type.
7174
7275
7376.. c :function :: int Py_IS_TYPE (PyObject *o, PyTypeObject *type)
Original file line number Diff line number Diff line change @@ -97,25 +97,41 @@ Optimizations
9797=============
9898
9999
100- Build and C API Changes
101- =======================
102-
103-
104-
105100Deprecated
106101==========
107102
108103
109-
110104Removed
111105=======
112106
113107
114-
115108Porting to Python 3.10
116109======================
117110
118111This section lists previously described changes and other bugfixes
119112that may require changes to your code.
120113
121114
115+
116+ Build Changes
117+ =============
118+
119+
120+ C API Changes
121+ =============
122+
123+ New Features
124+ ------------
125+
126+
127+ Porting to Python 3.10
128+ ----------------------
129+
130+ * Since :c:func: `Py_TYPE() ` is changed to the inline static function,
131+ ``Py_TYPE(obj) = new_type `` must be replaced with ``Py_SET_TYPE(obj, new_type) ``:
132+ see :c:func: `Py_SET_TYPE() ` (available since Python 3.9).
133+ (Contributed by Dong-hee Na in :issue: `39573 `.)
134+
135+
136+ Removed
137+ -------
Original file line number Diff line number Diff line change @@ -121,9 +121,13 @@ typedef struct {
121121#define _PyVarObject_CAST (op ) ((PyVarObject*)(op))
122122
123123#define Py_REFCNT (ob ) (_PyObject_CAST(ob)->ob_refcnt)
124- #define Py_TYPE (ob ) (_PyObject_CAST(ob)->ob_type)
125124#define Py_SIZE (ob ) (_PyVarObject_CAST(ob)->ob_size)
126125
126+ static inline PyTypeObject * _Py_TYPE (const PyObject * ob ) {
127+ return ob -> ob_type ;
128+ }
129+ #define Py_TYPE (ob ) _Py_TYPE(_PyObject_CAST_CONST(ob))
130+
127131static inline int _Py_IS_TYPE (const PyObject * ob , const PyTypeObject * type ) {
128132 return ob -> ob_type == type ;
129133}
Original file line number Diff line number Diff line change 1+ :c:func: `Py_TYPE() ` is changed to the inline static function. Patch by
2+ Dong-hee Na.
You can’t perform that action at this time.
0 commit comments