Convenience facilities related to Python functions.
Project description
Convenience facilities related to Python functions.
Latest release 20220619: @trace: rename some parameters, add with_caller.
Function callif(doit, func, *a, **kw)
Call func(*a,**kw) if doit is true
otherwise just print it out.
The parameter func may be preceeded optionally by a dict
containing modes. The current modes are:
'print': the print function, default the builtinprint
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 func_a_kw_fmt(func, *a, **kw)
Prepare a percent-format string and associated argument list
describing a call to func(*a,**kw).
Return format,args.
The func argument can also be a string,
presumably a prepared description of func such as funccite(func).
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 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: 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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cs.py.func-20220619.tar.gz.
File metadata
- Download URL: cs.py.func-20220619.tar.gz
- Upload date:
- Size: 5.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.1 readme-renderer/30.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.7 tqdm/4.62.3 importlib-metadata/4.8.2 keyring/23.3.0 rfc3986/1.5.0 colorama/0.4.4 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a489e065af204bf46b143ed3f70cc5812794a17793e098ba11b01eaa46279479
|
|
| MD5 |
780542a2ff3e32c2b7f4e471ec510f33
|
|
| BLAKE2b-256 |
18665b76bee85a2351ec62bc9bbcd48064bc840b0676b02e4942a681eba4547d
|
File details
Details for the file cs.py.func-20220619-py3-none-any.whl.
File metadata
- Download URL: cs.py.func-20220619-py3-none-any.whl
- Upload date:
- Size: 5.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.1 readme-renderer/30.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.7 tqdm/4.62.3 importlib-metadata/4.8.2 keyring/23.3.0 rfc3986/1.5.0 colorama/0.4.4 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e7b203dd28ee6182b08b880075f2cee43c3f33342bc46acca5b776d17082dcd8
|
|
| MD5 |
bd726169d6c2ee77348df7e5b8ce0313
|
|
| BLAKE2b-256 |
ee839b3749284bb805d97c6586f057d4631dbde9864c5ee31a158104ffe0c9e0
|