meta

module fastcore.meta in fastcore

Classes

builtins.object
    AutoInit
builtins.type(builtins.object)
    FixSigMeta
        BypassNewMeta
        NewChkMeta
        PrePostInitMeta

AutoInit

class AutoInit(builtins.object)
 |  AutoInit(*args, **kwargs)
 |  
 |  Same as `object`, but no need for subclasses to call `super().__init__`
 |  
 |  Methods defined here:
 |  
 |  

AutoInit.__pre_init__

 |  
 |  __pre_init__(self, *args, **kwargs)
 |  
 |  ----------------------------------------------------------------------
 |  Data descriptors defined here:
 |  
 |  __dict__
 |      dictionary for instance variables (if defined)
 |  
 |  __weakref__
 |      list of weak references to the object (if defined)

BypassNewMeta

class BypassNewMeta(FixSigMeta)
 |  BypassNewMeta(name, bases, dict)
 |  
 |  Metaclass: casts `x` to this class if it's of type `cls._bypass_type`
 |  
 |  Method resolution order:
 |      BypassNewMeta
 |      FixSigMeta
 |      builtins.type
 |      builtins.object
 |  
 |  Methods defined here:
 |  
 |  

BypassNewMeta.__call__

 |  
 |  __call__(cls, x=None, *args, **kwargs)
 |      Call self as a function.
 |  
 |  ----------------------------------------------------------------------
 |  Static methods inherited from FixSigMeta:
 |  
 |  

FixSigMeta.__new__

 |  
 |  __new__(cls, name, bases, dict)
 |      Create and return a new object.  See help(type) for accurate signature.
 |  
 |  ----------------------------------------------------------------------
 |  Methods inherited from builtins.type:
 |  
 |  

type.__delattr__

 |  
 |  __delattr__(self, name, /)
 |      Implement delattr(self, name).
 |  
 |  

type.__dir__

 |  
 |  __dir__(self, /)
 |      Specialized __dir__ implementation for types.
 |  
 |  

type.__getattribute__

 |  
 |  __getattribute__(self, name, /)
 |      Return getattr(self, name).
 |  
 |  

type.__init__

 |  
 |  __init__(self, /, *args, **kwargs)
 |      Initialize self.  See help(type(self)) for accurate signature.
 |  
 |  

type.__instancecheck__

 |  
 |  __instancecheck__(self, instance, /)
 |      Check if an object is an instance.
 |  
 |  

type.__repr__

 |  
 |  __repr__(self, /)
 |      Return repr(self).
 |  
 |  

type.__setattr__

 |  
 |  __setattr__(self, name, value, /)
 |      Implement setattr(self, name, value).
 |  
 |  

type.__sizeof__

 |  
 |  __sizeof__(self, /)
 |      Return memory consumption of the type object.
 |  
 |  

type.__subclasscheck__

 |  
 |  __subclasscheck__(self, subclass, /)
 |      Check if a class is a subclass.
 |  
 |  

type.__subclasses__

 |  
 |  __subclasses__(self, /)
 |      Return a list of immediate subclasses.
 |  
 |  

type.mro

 |  
 |  mro(self, /)
 |      Return a type's method resolution order.
 |  
 |  ----------------------------------------------------------------------
 |  Class methods inherited from builtins.type:
 |  
 |  

BypassNewMeta.__prepare__

 |  
 |  __prepare__(...) from builtins.type
 |      __prepare__() -> dict
 |      used to create the namespace for the class statement
 |  
 |  ----------------------------------------------------------------------
 |  Data descriptors inherited from builtins.type:
 |  
 |  __abstractmethods__
 |  
 |  __dict__
 |  
 |  __text_signature__
 |  
 |  ----------------------------------------------------------------------
 |  Data and other attributes inherited from builtins.type:
 |  
 |  __base__ = <class 'fastcore.meta.FixSigMeta'>
 |      A metaclass that fixes the signature on classes that override `__new__`
 |  
 |  
 |  __bases__ = (<class 'fastcore.meta.FixSigMeta'>,)
 |  
 |  __basicsize__ = 880
 |  
 |  __dictoffset__ = 264
 |  
 |  __flags__ = 2148292096
 |  
 |  __itemsize__ = 40
 |  
 |  __mro__ = (<class 'fastcore.meta.BypassNewMeta'>, <class 'fastcore.met...
 |  
 |  __weakrefoffset__ = 368

FixSigMeta

class FixSigMeta(builtins.type)
 |  FixSigMeta(name, bases, dict)
 |  
 |  A metaclass that fixes the signature on classes that override `__new__`
 |  
 |  Method resolution order:
 |      FixSigMeta
 |      builtins.type
 |      builtins.object
 |  
 |  Static methods defined here:
 |  
 |  

FixSigMeta.__new__

 |  
 |  __new__(cls, name, bases, dict)
 |      Create and return a new object.  See help(type) for accurate signature.
 |  
 |  ----------------------------------------------------------------------
 |  Methods inherited from builtins.type:
 |  
 |  

type.__call__

 |  
 |  __call__(self, /, *args, **kwargs)
 |      Call self as a function.
 |  
 |  

type.__delattr__

 |  
 |  __delattr__(self, name, /)
 |      Implement delattr(self, name).
 |  
 |  

type.__dir__

 |  
 |  __dir__(self, /)
 |      Specialized __dir__ implementation for types.
 |  
 |  

type.__getattribute__

 |  
 |  __getattribute__(self, name, /)
 |      Return getattr(self, name).
 |  
 |  

type.__init__

 |  
 |  __init__(self, /, *args, **kwargs)
 |      Initialize self.  See help(type(self)) for accurate signature.
 |  
 |  

type.__instancecheck__

 |  
 |  __instancecheck__(self, instance, /)
 |      Check if an object is an instance.
 |  
 |  

type.__repr__

 |  
 |  __repr__(self, /)
 |      Return repr(self).
 |  
 |  

type.__setattr__

 |  
 |  __setattr__(self, name, value, /)
 |      Implement setattr(self, name, value).
 |  
 |  

type.__sizeof__

 |  
 |  __sizeof__(self, /)
 |      Return memory consumption of the type object.
 |  
 |  

type.__subclasscheck__

 |  
 |  __subclasscheck__(self, subclass, /)
 |      Check if a class is a subclass.
 |  
 |  

type.__subclasses__

 |  
 |  __subclasses__(self, /)
 |      Return a list of immediate subclasses.
 |  
 |  

type.mro

 |  
 |  mro(self, /)
 |      Return a type's method resolution order.
 |  
 |  ----------------------------------------------------------------------
 |  Class methods inherited from builtins.type:
 |  
 |  

FixSigMeta.__prepare__

 |  
 |  __prepare__(...) from builtins.type
 |      __prepare__() -> dict
 |      used to create the namespace for the class statement
 |  
 |  ----------------------------------------------------------------------
 |  Data descriptors inherited from builtins.type:
 |  
 |  __abstractmethods__
 |  
 |  __dict__
 |  
 |  __text_signature__
 |  
 |  ----------------------------------------------------------------------
 |  Data and other attributes inherited from builtins.type:
 |  
 |  __base__ = <class 'type'>
 |      type(object) -> the object's type
 |      type(name, bases, dict, **kwds) -> a new type
 |  
 |  
 |  __bases__ = (<class 'type'>,)
 |  
 |  __basicsize__ = 880
 |  
 |  __dictoffset__ = 264
 |  
 |  __flags__ = 2148292096
 |  
 |  __itemsize__ = 40
 |  
 |  __mro__ = (<class 'fastcore.meta.FixSigMeta'>, <class 'type'>, <class ...
 |  
 |  __weakrefoffset__ = 368

NewChkMeta

class NewChkMeta(FixSigMeta)
 |  NewChkMeta(name, bases, dict)
 |  
 |  Metaclass to avoid recreating object passed to constructor
 |  
 |  Method resolution order:
 |      NewChkMeta
 |      FixSigMeta
 |      builtins.type
 |      builtins.object
 |  
 |  Methods defined here:
 |  
 |  

NewChkMeta.__call__

 |  
 |  __call__(cls, x=None, *args, **kwargs)
 |      Call self as a function.
 |  
 |  ----------------------------------------------------------------------
 |  Static methods inherited from FixSigMeta:
 |  
 |  

FixSigMeta.__new__

 |  
 |  __new__(cls, name, bases, dict)
 |      Create and return a new object.  See help(type) for accurate signature.
 |  
 |  ----------------------------------------------------------------------
 |  Methods inherited from builtins.type:
 |  
 |  

type.__delattr__

 |  
 |  __delattr__(self, name, /)
 |      Implement delattr(self, name).
 |  
 |  

type.__dir__

 |  
 |  __dir__(self, /)
 |      Specialized __dir__ implementation for types.
 |  
 |  

type.__getattribute__

 |  
 |  __getattribute__(self, name, /)
 |      Return getattr(self, name).
 |  
 |  

type.__init__

 |  
 |  __init__(self, /, *args, **kwargs)
 |      Initialize self.  See help(type(self)) for accurate signature.
 |  
 |  

type.__instancecheck__

 |  
 |  __instancecheck__(self, instance, /)
 |      Check if an object is an instance.
 |  
 |  

type.__repr__

 |  
 |  __repr__(self, /)
 |      Return repr(self).
 |  
 |  

type.__setattr__

 |  
 |  __setattr__(self, name, value, /)
 |      Implement setattr(self, name, value).
 |  
 |  

type.__sizeof__

 |  
 |  __sizeof__(self, /)
 |      Return memory consumption of the type object.
 |  
 |  

type.__subclasscheck__

 |  
 |  __subclasscheck__(self, subclass, /)
 |      Check if a class is a subclass.
 |  
 |  

type.__subclasses__

 |  
 |  __subclasses__(self, /)
 |      Return a list of immediate subclasses.
 |  
 |  

type.mro

 |  
 |  mro(self, /)
 |      Return a type's method resolution order.
 |  
 |  ----------------------------------------------------------------------
 |  Class methods inherited from builtins.type:
 |  
 |  

NewChkMeta.__prepare__

 |  
 |  __prepare__(...) from builtins.type
 |      __prepare__() -> dict
 |      used to create the namespace for the class statement
 |  
 |  ----------------------------------------------------------------------
 |  Data descriptors inherited from builtins.type:
 |  
 |  __abstractmethods__
 |  
 |  __dict__
 |  
 |  __text_signature__
 |  
 |  ----------------------------------------------------------------------
 |  Data and other attributes inherited from builtins.type:
 |  
 |  __base__ = <class 'fastcore.meta.FixSigMeta'>
 |      A metaclass that fixes the signature on classes that override `__new__`
 |  
 |  
 |  __bases__ = (<class 'fastcore.meta.FixSigMeta'>,)
 |  
 |  __basicsize__ = 880
 |  
 |  __dictoffset__ = 264
 |  
 |  __flags__ = 2148292096
 |  
 |  __itemsize__ = 40
 |  
 |  __mro__ = (<class 'fastcore.meta.NewChkMeta'>, <class 'fastcore.meta.F...
 |  
 |  __weakrefoffset__ = 368

PrePostInitMeta

class PrePostInitMeta(FixSigMeta)
 |  PrePostInitMeta(name, bases, dict)
 |  
 |  A metaclass that calls optional `__pre_init__` and `__post_init__` methods
 |  
 |  Method resolution order:
 |      PrePostInitMeta
 |      FixSigMeta
 |      builtins.type
 |      builtins.object
 |  
 |  Methods defined here:
 |  
 |  

PrePostInitMeta.__call__

 |  
 |  __call__(cls, *args, **kwargs)
 |      Call self as a function.
 |  
 |  ----------------------------------------------------------------------
 |  Static methods inherited from FixSigMeta:
 |  
 |  

FixSigMeta.__new__

 |  
 |  __new__(cls, name, bases, dict)
 |      Create and return a new object.  See help(type) for accurate signature.
 |  
 |  ----------------------------------------------------------------------
 |  Methods inherited from builtins.type:
 |  
 |  

type.__delattr__

 |  
 |  __delattr__(self, name, /)
 |      Implement delattr(self, name).
 |  
 |  

type.__dir__

 |  
 |  __dir__(self, /)
 |      Specialized __dir__ implementation for types.
 |  
 |  

type.__getattribute__

 |  
 |  __getattribute__(self, name, /)
 |      Return getattr(self, name).
 |  
 |  

type.__init__

 |  
 |  __init__(self, /, *args, **kwargs)
 |      Initialize self.  See help(type(self)) for accurate signature.
 |  
 |  

type.__instancecheck__

 |  
 |  __instancecheck__(self, instance, /)
 |      Check if an object is an instance.
 |  
 |  

type.__repr__

 |  
 |  __repr__(self, /)
 |      Return repr(self).
 |  
 |  

type.__setattr__

 |  
 |  __setattr__(self, name, value, /)
 |      Implement setattr(self, name, value).
 |  
 |  

type.__sizeof__

 |  
 |  __sizeof__(self, /)
 |      Return memory consumption of the type object.
 |  
 |  

type.__subclasscheck__

 |  
 |  __subclasscheck__(self, subclass, /)
 |      Check if a class is a subclass.
 |  
 |  

type.__subclasses__

 |  
 |  __subclasses__(self, /)
 |      Return a list of immediate subclasses.
 |  
 |  

type.mro

 |  
 |  mro(self, /)
 |      Return a type's method resolution order.
 |  
 |  ----------------------------------------------------------------------
 |  Class methods inherited from builtins.type:
 |  
 |  

PrePostInitMeta.__prepare__

 |  
 |  __prepare__(...) from builtins.type
 |      __prepare__() -> dict
 |      used to create the namespace for the class statement
 |  
 |  ----------------------------------------------------------------------
 |  Data descriptors inherited from builtins.type:
 |  
 |  __abstractmethods__
 |  
 |  __dict__
 |  
 |  __text_signature__
 |  
 |  ----------------------------------------------------------------------
 |  Data and other attributes inherited from builtins.type:
 |  
 |  __base__ = <class 'fastcore.meta.FixSigMeta'>
 |      A metaclass that fixes the signature on classes that override `__new__`
 |  
 |  
 |  __bases__ = (<class 'fastcore.meta.FixSigMeta'>,)
 |  
 |  __basicsize__ = 880
 |  
 |  __dictoffset__ = 264
 |  
 |  __flags__ = 2148292096
 |  
 |  __itemsize__ = 40
 |  
 |  __mro__ = (<class 'fastcore.meta.PrePostInitMeta'>, <class 'fastcore.m...
 |  
 |  __weakrefoffset__ = 368

Functions

anno_dict

anno_dict(f)
    `__annotation__ dictionary with `empty` cast to `None`, returning empty if doesn't exist

delegates

delegates(to: function = None, keep=False, but: list = None)
    Decorator: replace `**kwargs` in signature with params from `to`

empty2none

empty2none(p)
    Replace `Parameter.empty` with `None`

funcs_kwargs

funcs_kwargs(as_method=False)
    Replace methods in `cls._methods` with those from `kwargs`

method

method(f)
    Mark `f` as a method

test_sig

test_sig(f, b)
    Test the signature of an object

use_kwargs

use_kwargs(names, keep=False)
    Decorator: replace `**kwargs` in signature with `names` params

use_kwargs_dict

use_kwargs_dict(keep=False, **kwargs)
    Decorator: replace `**kwargs` in signature with `names` params