Skip to main content

@export decorator that adds a function or class to __all__

Project description

Explicit module exports

Installation

Requires python>=3.8

pip install exports

Usage

>>> from exports import export

Now you can use it to add to __all__ as

  • function decorator

    >>> @export
    ... def spam():
    ...     ...
    
  • class decorator:

    >>> @export
    ... class Ham:
    ...     ...
    
  • by name:

    >>> from functools import reduce as fold
    >>> export('fold')
    

Behaviour

If the module has no all, it is created. Otherwise, __all__ is converted to a list, and the export is appended.

Caveats

Exporting a function or class directly relies on the name attribute, so consider the following example:

>>> def eggs():
...     ...
>>> fake_eggs = eggs

If we want to export fake_eggs, then this will not work:

>>> export(fake_eggs)  # BAD: this will add 'eggs' to __all__

In such cases, use the name instead:

>>> export('fake_eggs')  # GOOD

You'll be safe if you either

  • decorate a function or a class directly with @export,
  • pass the name string when using plain export('...') calls.

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

python-exports-1.0.0.tar.gz (3.5 kB view details)

Uploaded Source

Built Distribution

python_exports-1.0.0-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

Details for the file python-exports-1.0.0.tar.gz.

File metadata

  • Download URL: python-exports-1.0.0.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.10.2 Linux/5.13.0-35-generic

File hashes

Hashes for python-exports-1.0.0.tar.gz
Algorithm Hash digest
SHA256 ffb8dba409920ddb7e26eeda0f18f61ce54351d4a3094200cde0e2daa5b1f147
MD5 20ff98ac668ba3d64baea6909d3e8b11
BLAKE2b-256 8786e5563dca419bea8da41f04eb67ea689013f0afc81484858dd44cddf20ebb

See more details on using hashes here.

File details

Details for the file python_exports-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: python_exports-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 3.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.10.2 Linux/5.13.0-35-generic

File hashes

Hashes for python_exports-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9fbf951eb3f06454d1b5349fd017064a70f222b1b0ec1f65f6cc516c96f91a45
MD5 6f1546f1e4aa366f03a6051f496363b9
BLAKE2b-256 7558be141994059db75b52cc20b44e2a7388aeff90830c20e02910696f411e24

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