stubber.codemod.add_method

Codemod to add methods to a classes.

Used to add methods that are documented, but are not reported by the firmware, so they are also not present in the firmware stubs.

Classes

CallFinder

Find the Pin.__call__ method and extract it from a (machine) module.

CallAdder

Add a __call__ method to a class if it is missing.

Module Contents

class stubber.codemod.add_method.CallFinder

Bases: libcst.matchers.MatcherDecoratableTransformer

Find the Pin.__call__ method and extract it from a (machine) module.

class_name: str = 'Pin'
method_name: str = '__call__'
call_meth: libcst.FunctionDef | None = None
detect_call(node: libcst.FunctionDef) None

find the __call__ method and store it.

Parameters:

node (libcst.FunctionDef)

Return type:

None

class stubber.codemod.add_method.CallAdder(call_meth: libcst.FunctionDef)

Bases: libcst.matchers.MatcherDecoratableTransformer

Add a __call__ method to a class if it is missing.

Parameters:

call_meth (libcst.FunctionDef)

class_name = 'Pin'
has_call = 0
call_meth
detect_call(node: libcst.FunctionDef) None

Detect if the class already has a __call__ method.

Parameters:

node (libcst.FunctionDef)

Return type:

None

add_call(original_node: libcst.ClassDef, updated_node: libcst.ClassDef) libcst.ClassDef

Add the __call__ method to the class if it is not already there.

Parameters:
  • original_node (libcst.ClassDef)

  • updated_node (libcst.ClassDef)

Return type:

libcst.ClassDef