Skip to main content

Convenience facilities related to Python functions.

Latest release 20210717:

  • Move @trace from debug to py.func, defer log call imports to avoid loops.
  • Drop cs.pfx requirement, import opportunisticly with fallback.

Function callmethod_if(o, method, default=None, a=None, kw=None)

Call the named method on the object o if it exists.

If it does not exist, return default (which defaults to None). Otherwise call getattr(o, method)(*a, **kw). a defaults to (). kw defaults to {}.

Function derived_from(property_name)

A property which must be recomputed if the revision of another property exceeds the snapshot revision.

Function derived_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.

Function funccite(func)

Return a citation for a function (name and code location).

Function funcname(func)

Return a name for the supplied function func. Several objects do not have a name attribute, such as partials.

Function prop(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.

Function returns_bool(func)

Decorator for functions which should return Booleans.

Function returns_str(func)

Decorator for functions which should return strings.

Function returns_type(func, basetype)

Decrator which checks that a function returns values of type basetype.

Function trace(*da, **dkw)

Decorator to report the call and return of a function.

Function yields_str(func)

Decorator for generators which should yield strings.

Function yields_type(func, basetype)

Decorator which checks that a generator yields values of type basetype.

Release Log

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: prefer func.__qualname__ over func.__name__

Release 20190729: funccite: handle callables with no code attribute.

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.

Release files for cs-py-func 20210717

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cs-py-func 20210717
File Size Uploaded
cs.py.func-20210717.tar.gz 4.8 kB Details

Release files / cs.py.func-20210717.tar.gz

Download URL cs.py.func-20210717.tar.gz
Size 4.8 kB
Tags Source
SHA-256 checksum
How to use checksums
2de8be1c3e465eeb89bf6e31c61a3fb6b26c3ee893992e4e38976a84bd7cc0c5
BLAKE2b-256 checksum
How to use checksums
06ab1260577e739dffc9837e0359f168dd686e0b7862c39ad27a1e84982de2ed
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.55.0 CPython/3.9.6
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page