File tree 4 files changed +37
-12
lines changed
Misc/NEWS.d/next/Core and Builtins
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.
62
62
See documentation of :c:type: `PyVarObject ` above.
63
63
64
64
65
- .. c :macro :: Py_TYPE(o)
65
+ .. c :function :: PyTypeObject* Py_TYPE (const PyObject * o)
66
66
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.
69
70
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.
71
74
72
75
73
76
.. 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
97
97
=============
98
98
99
99
100
- Build and C API Changes
101
- =======================
102
-
103
-
104
-
105
100
Deprecated
106
101
==========
107
102
108
103
109
-
110
104
Removed
111
105
=======
112
106
113
107
114
-
115
108
Porting to Python 3.10
116
109
======================
117
110
118
111
This section lists previously described changes and other bugfixes
119
112
that may require changes to your code.
120
113
121
114
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 {
121
121
#define _PyVarObject_CAST (op ) ((PyVarObject*)(op))
122
122
123
123
#define Py_REFCNT (ob ) (_PyObject_CAST(ob)->ob_refcnt)
124
- #define Py_TYPE (ob ) (_PyObject_CAST(ob)->ob_type)
125
124
#define Py_SIZE (ob ) (_PyVarObject_CAST(ob)->ob_size)
126
125
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
+
127
131
static inline int _Py_IS_TYPE (const PyObject * ob , const PyTypeObject * type ) {
128
132
return ob -> ob_type == type ;
129
133
}
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