Skip to main content

Convenience facilities related to Python functions. * funccite: cite a function (name and code location) * @prop: replacement for @property which turns internal AttributeErrors into RuntimeErrors * some decorators to verify the return types of functions

Project description

Convenience facilities related to Python functions.

  • funccite: cite a function (name and code location)
  • @prop: replacement for @property which turns internal AttributeErrors into RuntimeErrors
  • some decorators to verify the return types of functions

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cs.py.func-20181231.tar.gz (3.6 kB view details)

Uploaded Source

File details

Details for the file cs.py.func-20181231.tar.gz.

File metadata

  • Download URL: cs.py.func-20181231.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.23.0 CPython/3.6.6

File hashes

Hashes for cs.py.func-20181231.tar.gz
Algorithm Hash digest
SHA256 ff38cad7ec62e5c583b7b33e8cf793b529efc78665a1d7bd88f0505956ce454f
MD5 5d4a1b7b9eaebfc3092ceaaa1ab41fb2
BLAKE2b-256 f5a033e11c1bd2e8b7a4b510a06e844cb3549e589317689772002e558cc43c30

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page