Skip to main content

Convenience facilities related to Python functions.

Short summary:

  • akw: A trite class to store positional and keyword arguments.

  • callif: Call func(*a,**kw) if doit is true otherwise just print it out.

  • callmethod_if: Call the named method on the object obj if 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 to func(*a,**kw).

  • func_a_kw_fmt: Prepare a percent-format string and associated argument list describing a call to func(*a,**kw). Return format,args.

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

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

  • prop: A substitute for the builtin @property.

Functions

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 builtin print

callmethod_if(obj, method, default=None, a=None, kw=None)

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

If it does not exist, return default (which defaults to None). Otherwise call getattr(obj, method)(*a, **kw). a defaults to (). kw defaults 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 to func(*a,**kw).

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.

funccite(func)

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

funcname(func)

Return a name for the supplied function func. 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.

Classes

class akw

A trite class to store positional and keyword arguments.

It's a constant annoyance to me that there no neat way to store a pairing of positional and keyword arguments for use with a function. You can eaily store a sequence, a mapping, and you can store a function with arguments using functools.partial.

Example:

>>> args = akw(1, 2, x=3, z=4)
>>> args
akw(*(1, 2),**{'x': 3, 'z': 4})
>>> args.args
(1, 2)
>>> args.kwargs
{'x': 3, 'z': 4}
>>> import sys
>>> prakw=akw(1, 2, file=sys.stdout)
>>> prakw(print, 3)
1 2 3

akw.__call__(self, func, *cargs, **ckwargs)

Call func with self.args and cargs as positional arguments and self.kwargs and ckwargs as keyword arguments.

Metadata

Release files for cs-py-func 20261030

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 20261030
File Size Uploaded Provenance Actions
cs_py_func-20261030.tar.gz 4.0 kB Without provenance Details for cs_py_func-20261030.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cs-py-func 20261030
File Interpreter ABI Platform Actions
cs_py_func-20261030-py3-none-any.whl Python 3 none any Details for cs_py_func-20261030-py3-none-any.whl

Total release size: 9.2 kB

Release files / cs_py_func-20261030.tar.gz

Download URL cs_py_func-20261030.tar.gz
Size 4.0 kB
Tags Source
SHA-256 checksum
How to use checksums
cb9ed869ca018c7594cad03a6c42a64ffb74dad72afe60c4bf42283b0f69c3d1
BLAKE2b-256 checksum
How to use checksums
32ebbb4ecaabf63890e2fc7de271ddf60beacfd1c11570571f9695d670156c37
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.1

Release files / cs_py_func-20261030-py3-none-any.whl

Download URL cs_py_func-20261030-py3-none-any.whl
Size 5.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2e2ef9cccfcfca65cccba4baaefefe1de0e8edf7c31dbcebff9d3ecf1254ae19
BLAKE2b-256 checksum
How to use checksums
4214d25305bca69bbefabf82ea048137f8d5f8c93731c9a43c112ddcf5f8d216
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.1

Security for cs-py-func 20261030

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.

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