consts-everywhere
Create const variables everywhere. This is not just a __setattr__ trick that only makes it possible to create const members. You can also create local and global consts.
Installation
pip install consts-everywhere
How To Use
We have a proxy class:
class Const(wrapped)
This class inherits a variant of ObjectProxy from wrapt. Along with all augmented assignment operators, this class also overloads the normal assignment operator (=) thanks to assign-overload. wrapped can be any object and the resulting instance of this class will act like wrapped in every way. If you use this class, you need to call consts_everywhere.patch_and_reload_module(). consts_everywhere monkeypatches assign_overload.patch_and_reload_module() to make it possible to define global Const objects. Since it is monkeypatched you can also access this function from assign_overload module. You can find documentation about this function in assign-overload. Usage example:
import consts_everywhere
def main():
a = consts_everywhere.Const(10)
print(a) # prints 10
a = 20 # Error
if consts_everywhere.patch_and_reload_module():
main()
One thing to note is if you assign a variable holding a Const instance to a new variable, new variable takes the value of the Const instance, not the value of its underlying object. However, most operators return the underlying object. Example:
import consts_everywhere
def main():
a = consts_everywhere.Const(10)
print(type(a+5)) # prints int
b = a
print(type(b)) # prints Const
if consts_everywhere.patch_and_reload_module():
main()
If you want to access the underlying object, use the __wrapped__ attribute:
import consts_everywhere
def main():
a = consts_everywhere.Const(10)
b = a.__wrapped__
print(type(b)) # prints int
if consts_everywhere.patch_and_reload_module():
main()
Const is also compatible with typeguard. Function argument type enforcement example:
import typeguard
import consts_everywhere
@typeguard.typechecked
def test4(a: consts_everywhere.Const[int]):
pass
def main():
a = consts_everywhere.Const(10)
b = consts_everywhere.Const("abc")
test4(a) # Ok
test4(b) # Error
if consts_everywhere.patch_and_reload_module():
main()
Metadata
Release files for consts-everywhere 1.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| consts_everywhere-1.0.2.tar.gz | 37.3 kB | Without provenance | Details for consts_everywhere-1.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| consts_everywhere-1.0.2-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details for consts_everywhere-1.0.2-py2.py3-none-any.whl |
Total release size: 80.5 kB
Release files / consts_everywhere-1.0.2.tar.gz
| Download URL | consts_everywhere-1.0.2.tar.gz |
|---|---|
| Size | 37.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4589619b80de30888d536ee940acbeea51120c8ef271ffe5992be694b2da3e9c
|
|
BLAKE2b-256 checksum How to use checksums |
5320cd2ca911d8e18dd074980a5a6b5fc27e08583ae099242eef24a9a9a2840d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.0
|
Release files / consts_everywhere-1.0.2-py2.py3-none-any.whl
| Download URL | consts_everywhere-1.0.2-py2.py3-none-any.whl |
|---|---|
| Size | 43.1 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
70b73e57cd2dd780718bf00714d22da07738176436f4b310a83aa3ac76ca4040
|
|
BLAKE2b-256 checksum How to use checksums |
2cedabff19f49a48d276ee4890190878ed6cdc7423e420e289dac10fe674c844
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.0
|
Security for consts-everywhere 1.0.2
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.