Convenience facilities related to Python functions.
Latest release 20240630: funcname: include the module name, handle functions with no module.
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(func, *a, **kw)
Return a string representing a call to func(*a,**kw).
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,
typically a prepared description of func such as funccite(func).
Note: the returned args is a list for easy incorporation
into further arguments. The % operator requires a tuple.
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.
Release Log
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.
Metadata
Release files for cs-py-func 20240630
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| cs.py.func-20240630.tar.gz | 5.0 kB | Without provenance | Details for cs.py.func-20240630.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| cs.py.func-20240630-py3-none-any.whl | Python 3 | none | any | Details for cs.py.func-20240630-py3-none-any.whl |
Total release size: 10.4 kB
Release files / cs.py.func-20240630.tar.gz
| Download URL | cs.py.func-20240630.tar.gz |
|---|---|
| Size | 5.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
57409dfab78c980fe97fa4dd21c208f469cbdad5aa8bde801df431d950675f52
|
|
BLAKE2b-256 checksum How to use checksums |
0f98ff6e07d40c8eb05c304574007bf745f2ef3b11012dabf16d006fc12a0d3f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.6
|
Release files / cs.py.func-20240630-py3-none-any.whl
| Download URL | cs.py.func-20240630-py3-none-any.whl |
|---|---|
| Size | 5.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ebcd26cf26d147385b3969b454dd9b8816936534c414b1dbd9679505fa7a5371
|
|
BLAKE2b-256 checksum How to use checksums |
c63e6e03bef1abf5ebe49371ae9250f0d40326e239b9bd7579d5e9e37a221670
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.6
|
Security for cs-py-func 20240630
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.