Package: cs.py.func
Convenience facilities related to Python functions.Latest release 20230331:
Drop @trace, moved to cs.debug.Functioncallif(doit, func, *a, **kw)Callfunc(*a,**kw)ifdoitis true
otherwise just print it out.The parameterfuncmay be preceeded optionally by adictcontaining modes. The current modes are:'print': the print function, default the builtinprintFunctioncallmethod_if(o, method, default=None, a=None, kw=None)Call the namedmethodon the objectoif it exists.If it does not exist, returndefault(which defaults to None).
Otherwise call getattr(o, method)(*a, **kw).adefaults to ().kwdefaults to {}.Functionderived_from(property_name)A property which must be recomputed
if the revision of another property exceeds the snapshot revision.Functionderived_property(func, original_revision_name='_revision', lock_name='_lock', property_name=None, unset_object=None)A property which must be recomputed
if the reference revision (attached to self)
exceeds the snapshot revision.Functionfunc_a_kw(func, *a, **kw)Return a string representing a call tofunc(*a,**kw).Functionfunc_a_kw_fmt(func, *a, **kw)Prepare a percent-format string and associated argument list
describing a call tofunc(*a,**kw).
Returnformat,args.Thefuncargument can also be a string,
typically a prepared description offuncsuch asfunccite(func).Note: the returnedargsis alistfor easy incorporation
into further arguments.  The%operator requires atuple.Functionfunccite(func)Return a citation for a function (name and code location).Functionfuncname(func)Return a name for the supplied functionfunc.
Several objects do not have anameattribute, such as partials.Functionprop(func)A substitute for the builtin @property.The builtin @property decorator lets internal AttributeErrors escape.
While that can support properties that appear to exist conditionally,
in practice this is almost never what I want, and it masks deeper errors.
Hence this wrapper for @property that transmutes internal AttributeErrors
into RuntimeErrors.Release LogRelease 20230331:
Drop @trace, moved to cs.debug.Release 20230210:
Drop the returns_* and yields_* decorators, these days type annotations and @typechecked are the go.Release 20221207:@trace: trace exceptions by default, previously false.Late import of cs.fs.shortpath to avoid import loop.New func_a_kw(func,*a,**kw) returning the formatted form of func_a_kw_fmt(func,*a,**kw).Release 20221118:
@trace: add indenting.Release 20220619:
@trace: rename some parameters, add with_caller.Release 20220311.1:
New callif(doit[,modes],func,*a,**kw) to call or print a function, used in -n/--dry-run stuff sometimes.Release 20220311:@trace: new pprint=False option to use pprint.pformat instead of repr for the return value.@trace: bugfix use of retval parameter.Release 20210913:
New func_a_kw_fmt(func,*a,**kw) imported from cs.pfx, hooked it into @trace.Release 20210906:
funcname: special case functools.partial, return concise name.Release 20210717:Move @trace from debug to py.func, defer log call imports to avoid loops.Drop cs.pfx requirement, import opportunisticly with fallback.Release 20200518:
funcname: preferfunc.__qualname__overfunc.__name__Release 20190729:
funccite: handle callables with nocodeattribute.Release 20190108:
Break import loop. Use cs.py3.raise_from for portability.Release 20181231:Some type specific convenience wrappers for yields_type and returns_type.Bugfix for @prop.Release 20170906.1:
Minor tweaks.Release 20170906:
Bugfix for @prop.Release 20170608:
New decorator @prop which works just like the builtin @property, but transmutes internal AttributeError into RuntimeError, unmasking many bugs.Release 20160828:
Use "install_requires" instead of "requires" in DISTINFO.Release 20150115:
First PyPI release.