@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.1.tar.gz
.
File metadata
- Download URL: python_exports-1.1.1.tar.gz
- Upload date:
- Size: 3.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.6.1 CPython/3.11.5 Linux/6.5.4-76060504-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 51f90f99c2a91d8f36450ce7b241091db1a5a9f85919aaad103cde0f180a713d |
|
MD5 | af7f98e9823dffdcd7fabe9f62f6827b |
|
BLAKE2b-256 | 9cd7fcd8877d289ff7a179e7a55d052c97e226767f258b4008ad4c8692421579 |
File details
Details for the file python_exports-1.1.1-py3-none-any.whl
.
File metadata
- Download URL: python_exports-1.1.1-py3-none-any.whl
- Upload date:
- Size: 3.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.6.1 CPython/3.11.5 Linux/6.5.4-76060504-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 25d0c0e78a9b8e89dfe74d4fda9370a6caed8aa86ce89d6311bf028dade7996b |
|
MD5 | 4e6424aa5b6b57c72cedf55d9f2e72db |
|
BLAKE2b-256 | bd68674dd5209b36a05b51879bbb007ed8c5455bfbfdbd7192568260d42319f6 |