@export decorator that adds a function or class to __all__
Project description
Explicit module exports
@export
- The DRY alternative to __all__
Installation
pip install python-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
Built Distribution
File details
Details for the file python_exports-1.1.0.tar.gz
.
File metadata
- Download URL: python_exports-1.1.0.tar.gz
- Upload date:
- Size: 3.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.11.2 Linux/6.2.6-76060206-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3825b8cf27cdd0a571d1257c0d010c99ca1926a3c41f1db6fbd14de98b09c3b6 |
|
MD5 | 73ac1df7406fd8f3548de22af010e473 |
|
BLAKE2b-256 | bf06b5ad46a8f5cea757eb425e172af2d050933f640e1990ef3b3046d9ea6c17 |
File details
Details for the file python_exports-1.1.0-py3-none-any.whl
.
File metadata
- Download URL: python_exports-1.1.0-py3-none-any.whl
- Upload date:
- Size: 3.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.11.2 Linux/6.2.6-76060206-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1bda8ace6793dc3aa5b2edb865ff11d1cd173ec2a8b96adcbc84427d5c67e038 |
|
MD5 | 8869de959f6ffd416c03c2c50a9774ba |
|
BLAKE2b-256 | 6cd13e013e12fdae176ee2d275c2b87a9204f24bae714e52f02bb5795f3d490f |