On this page
  1. types.new_class
  2. Import
  3. Signature & Overview
  4. Usage
  5. Gotchas
  6. REPL Inspect

types.new_class

Prev: types.MethodType | Up: types | Next: types.prepare_class
Rel: types.AsyncGeneratorType, types.BuiltinFunctionType, types.BuiltinMethodType, types.CapsuleType
Ref: docs.python.org — types.new_class
Tags: #public #python3 #stdlib #types


Import

import types
from types import new_class

Signature & Overview

types.new_class(name, bases=(), kwds=None, exec_body=None)

Create a class object dynamically using the appropriate metaclass.

Usage

import types

Dynamic = types.new_class('Dynamic', (object,), {}, lambda ns: ns.update(x=42))
assert Dynamic.x == 42

Gotchas

REPL Inspect

from types import new_class
help(new_class)

Linked from

Related notes