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

types.MethodType

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


Import

import types
from types import MethodType

Signature & Overview

types.MethodType(function, instance, /)

Create a bound instance method object.

Usage

import types

class Box:
    def __init__(self, v): self.v = v

b = Box(10)
bound = types.MethodType(lambda self: self.v * 2, b)
assert bound() == 20

Gotchas

REPL Inspect

from types import MethodType
help(MethodType)

Linked from

Related notes