A simple module for supporting forward references
Project description
py-forward_decl
A simple module for supporting forward references
What are those?
Forward references are references to objects that haven't been assigned yet. The reference is declared as just a name of the variable that has been forward declared. Forward declaration is a concept in many programming languages that declares the existance of a variable or a function before its value has been defined.
Why tho?
In 99% of cases when you would think of using forward references there is a better way to do it in Python. This is for the other 1%. Like when you need to reference a class from deep within an expression inside a class variable inside that class' definition. Also useful for recursive parser production rules that are defined using Python's semantics.
Installation
Install it using pip:
pip install forward-decl
Usage
Basic example:
var2 = FwDecl()
var1 = OpaqueFwRef("var2")
var2 = "Hello"
print(var1.get_ref()) # prints 'Hello'
A more useful case:
MyClass = FwDecl()
class MyClass:
clsReference = OpaqueFwRef("MyClass")
clsVar = "Hello"
print(MyClass.clsReference.get_ref().clsVar) # prints 'Hello'
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file forward_decl-0.1.2.tar.gz
.
File metadata
- Download URL: forward_decl-0.1.2.tar.gz
- Upload date:
- Size: 3.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fb72183d4b208417849de183836af6aab2fa646210a6750291b6cd3ecc3bbe87 |
|
MD5 | 0d73c31b9deaa06359d8154b97a1cbfe |
|
BLAKE2b-256 | acea5cc828229e70787fdca77d858b941345f2ca6f9245e241207b419da226c7 |