picop.cyfunction#

Function-object helpers.

picop.cyfunction.func_check(o)#

Return True if o is a Python function object (PyFunction_Check).

Parameters:

o (object)

Return type:

bool

picop.cyfunction.func_eq(a, b)#

Return True if a is b (function-object identity; CPython object.__eq__).

Parameters:
Return type:

bool

picop.cyfunction.func_get_annotations(op)#

Return the annotations dict of op, or None when unset.

Parameters:

op (object)

Return type:

object | None

picop.cyfunction.func_get_closure(op)#

Return closure cell tuple of op, or None.

Parameters:

op (object)

Return type:

object | None

picop.cyfunction.func_get_code(op)#

Return the code object of function op (owned ref).

Parameters:

op (object)

Return type:

object

picop.cyfunction.func_get_defaults(op)#

Return argument defaults tuple of op, or None.

Parameters:

op (object)

Return type:

object | None

picop.cyfunction.func_get_globals(op)#

Return the globals dict of function op (owned ref).

Parameters:

op (object)

Return type:

object

picop.cyfunction.func_get_kw_defaults(op)#

Return keyword-only defaults of op as a dict, or None.

Parameters:

op (object)

Return type:

object | None

picop.cyfunction.func_get_module(op)#

Return op.__module__ (owned ref), or None if unset.

Parameters:

op (object)

Return type:

object | None

picop.cyfunction.func_new(code, globals)#

Return a new function from code and globals (PyFunction_New).

Parameters:
Return type:

object

picop.cyfunction.func_new_with_qualname(code, globals, qualname)#

Return a new function from code, globals and qualname.

Notes

PyFunction_NewWithQualName — what the compiler uses for nested functions, so __qualname__ is correct from the start. globals must be a dict.

Parameters:
Return type:

object

picop.cyfunction.func_set_annotations(op, annotations)#

Set annotations on op (None or dict).

Notes

Returns 0 on success; errors raise — do not use the status as a bool.

Parameters:
Return type:

int

picop.cyfunction.func_set_closure(op, closure)#

Set closure on op (None or cell tuple).

Notes

Slower than the plain-Python equivalent lambda fn, c: 0 (Tier A 1.09x); function defaults without the Python attribute machinery.

Returns 0 on success; errors raise — do not use the status as a bool.

Parameters:
Return type:

int

picop.cyfunction.func_set_defaults(op, defaults)#

Set argument defaults on op (None or tuple).

Notes

Returns 0 on success; errors raise — do not use the status as a bool.

Parameters:
Return type:

int

picop.cyfunction.func_set_kw_defaults(op, defaults)#

Set keyword-only defaults on op (None or dict).

Notes

Returns 0 on success; errors raise — do not use the status as a bool.

Parameters:
Return type:

int