Skip to main content

Create and recursively fill a temporary directory

Project description

_Give your module the power of an object, with clod (and save a little typing too)._

Ever wanted to call a module directly, or index it? Or just sick of seeing from foo import foo in your examples?

clod is a tiny library that solves both these issues in one line of code, by extending a module with the methods and members of a Python object.

This is extremely handy for modules that primarily do one thing.

EXAMPLE: Make a module callable

# In your_module.py
import clod

A_CONSTANT = 23

@clod
def a_function(*args, **kwargs):
    print('a function!')
    return args, kwargs


# Test at the command line
>>> import your_module

>>> your_module(2, 3, a=5)
a function!
(2, 3), {'a': 5}

>>> assert your_module.A_CONSTANT == 23

EXAMPLE: Make a module look like an object

# In your_module.py
import clod

A_CONSTANT = 23

clod(list(), __name__)

# Test at the command line
>>> import your_module

>>> assert your_module == []

>>> assert your_module.A_CONSTANT == 23

>>> your_module.extend(range(3))

>>> print(your_module)
[0, 1, 2]

API

clod.clod(extension=None, name=None, properties=None, omit=None)

(clod.py, 96-177)

Extend the system module at name with any Python object.

The original module is replaced in sys.modules by a proxy class which delegates attributes, first to the extension, and then to the original module.

clod can also be used as a decorator, both with and without parameters.

ARGUMENTS
extension

The object whose methods and properties extend the namespace. This includes magic methods like __call__ and __getitem__.

name

The name of this symbol in sys.modules. If this is None then clod will use extension.__module__.

If the name argument is given, it should almost certainly be __name__.

properties

There is little need to use this argument.

Properties in this list are copied directly from the module into the custom class - they do not get overridden by the extension.

If properties is None, it defaults to clod.MODULE_PROPERTIES which seems to work well a lot of the time

omit

There is little need to use this argument.

A list of methods _not_ to delegate from the proxy to the extension.

(automatically generated by doks on 2020-07-18T15:46:33.018839)

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

clod-0.10.0.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

clod-0.10.0-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file clod-0.10.0.tar.gz.

File metadata

  • Download URL: clod-0.10.0.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/18.2 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.1

File hashes

Hashes for clod-0.10.0.tar.gz
Algorithm Hash digest
SHA256 70c7825b4582ff2e0f4749bb80edc1ce277df5562e33f93b34c95b29aa5075da
MD5 96a582a51b1a7fa6ff07ba1ff1ec005d
BLAKE2b-256 d72abf402d9b523543838da56f02f1f495213c7d7217ce8673097fea1c145aef

See more details on using hashes here.

File details

Details for the file clod-0.10.0-py3-none-any.whl.

File metadata

  • Download URL: clod-0.10.0-py3-none-any.whl
  • Upload date:
  • Size: 6.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/18.2 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.1

File hashes

Hashes for clod-0.10.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ca321cee22ed93192b3931ba84394c55649266801fd8c2fcaff665d47197d5e2
MD5 cd39d87b3dffb2fb46095887b7e7146b
BLAKE2b-256 7cf577ce76640b41db0e6987834842ec126a87f0bd92bffc1d0853191f7094ad

See more details on using hashes here.

Supported by

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