Convenience facilities related to Python functions.
Project description
Convenience facilities related to Python functions.
Latest release 20250914:
funcname: accomodate functions with no .__module__ attribute.
Short summary:
callif: Callfunc(*a,**kw)ifdoitis true otherwise just print it out.callmethod_if: Call the namedmethodon the objectobjif it exists.derived_from: A property which must be recomputed if the revision of another property exceeds the snapshot revision.derived_property: A property which must be recomputed if the reference revision (attached to self) exceeds the snapshot revision.func_a_kw: Return a string representing a call tofunc(*a,**kw).func_a_kw_fmt: Prepare a percent-format string and associated argument list describing a call tofunc(*a,**kw). Returnformat,args.funccite: Return a citation for a function (name and code location).funcname: Return a name for the supplied functionfunc. Several objects do not have a name attribute, such as partials.prop: A substitute for the builtin @property.
Module contents:
-
callif(doit, func, *a, **kw): Callfunc(*a,**kw)ifdoitis true otherwise just print it out.The parameter
funcmay be preceeded optionally by adictcontaining modes. The current modes are:'print': the print function, default the builtinprint
-
callmethod_if(obj, method, default=None, a=None, kw=None): Call the namedmethodon the objectobjif it exists.If it does not exist, return
default(which defaults to None). Otherwise call getattr(obj, method)(*a, **kw).adefaults to ().kwdefaults to {}. -
derived_from(property_name): A property which must be recomputed if the revision of another property exceeds the snapshot revision. -
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. -
func_a_kw(func, *a, **kw): Return a string representing a call tofunc(*a,**kw). -
func_a_kw_fmt(func, *a, **kw): Prepare a percent-format string and associated argument list describing a call tofunc(*a,**kw). Returnformat,args.The
funcargument can also be a string, typically a prepared description offuncsuch asfunccite(func).Note: the returned
argsis alistfor easy incorporation into further arguments. The%operator requires atuple. -
funccite(func): Return a citation for a function (name and code location). -
funcname(func): Return a name for the supplied functionfunc. Several objects do not have a name attribute, such as partials. -
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.
Release Log
Release 20250914:
funcname: accomodate functions with no .__module__ attribute.
Release 20250724:
- func_a_kw_fmt: shorten long %r, widen another field.
- Drop Python 2 support.
Release 20240630: funcname: include the module name, handle functions with no module.
Release 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: 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-20250914.tar.gz.
File metadata
- Download URL: cs_py_func-20250914.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
78947024050c524281eabf2b2cbc400c53e627b9ee4dca6eb16869453911ea0d
|
|
| MD5 |
5ccd7c943d354d9c5b7c90ca785c8eb3
|
|
| BLAKE2b-256 |
4ef0d27315a6a69e07165647e7304ccc62b1ea8ffd770bb4f90f9127931d621e
|
File details
Details for the file cs_py_func-20250914-py3-none-any.whl.
File metadata
- Download URL: cs_py_func-20250914-py3-none-any.whl
- Upload date:
- Size: 5.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2b7d119e973368c9734aa71b334d7926743f3d31ea0c6005c8de4a0d136e701a
|
|
| MD5 |
30d8e58b6f3cd6ddf866277e29b1c01b
|
|
| BLAKE2b-256 |
6d80768b544a3634966ebf3254daf4cb69482352449721a783c44f150a08743d
|