
type is not a C keyword nor a Python reserved keyword—it’s a descriptive identifier used in the Python C API to denote type objects (e.g., type PyTypeObject), and in Python it’s a built-in class name that can even be shadowed as a variable (though discouraged).
`type` is not a c keyword nor a python reserved keyword—it’s a descriptive identifier used in the python c api to denote type objects (e.g., `type pytypeobject`), and in python it’s a built-in class name that can even be shadowed as a variable (though discouraged).
In the Python C API documentation, the line type PyTypeObject does not mean that type is a keyword or a C language construct like struct or typedef. Instead, it’s a convention—a human-readable label indicating that PyTypeObject represents a type object, i.e., the C-level structure underlying Python classes and types. This usage predates any syntactic role of type in Python itself and serves purely as documentation-oriented notation.
For example, this snippet from the C API is not valid C code on its own:
type PyTypeObject; // ❌ Not legal C — 'type' is not a keyword or typedef
What’s actually defined in <object.h></object.h> is:
typedef struct _typeobject {
// ... fields ...
} PyTypeObject;So PyTypeObject is a typedef’d struct, and the word type in type PyTypeObject is simply an editorial annotation—not part of the syntax.
立即学习“Python免费学习笔记(深入)”;
In Python, type is a built-in class, not a reserved keyword:
>>> type(42) <class 'int'> >>> type <class 'type'> >>> type = "I just overwrote type!" # ✅ Valid (but dangerous!) >>> type(42) # ❌ AttributeError: 'str' object has no attribute '__call__'
⚠️ While technically allowed, reassigning type (or other built-ins like list, dict) breaks introspection and type checking—and should be avoided in production code.
One nuance: Starting with Python 3.12, type became a soft keyword—but only in the context of PEP 695 type parameter declarations:
type Point[T] = tuple[T, T] # ✅ 'type' is a soft keyword here x: type[int] = 42 # ❌ Still invalid — 'type' is NOT a soft keyword in annotations
Even then, soft keywords are context-sensitive: type remains freely usable as an identifier elsewhere (for type in types:, def func(type=None):, etc.).
In summary:
- In C API docs,
typeis a descriptive label, not syntax. - In Python,
typeis a built-in class—reassignable but strongly discouraged. - Since 3.12,
typegains soft-keyword status only intype X[...] = ...declarations—never globally.



















