Skip to main content

A set of small classes to represent Python runtime objects - modules, classes, functions, constants, and abstract instances - in a structured and consistent way.

Project description

python-runtime-entity-wrappers

A set of small classes to represent Python runtime objects - modules, classes, functions, constants, and abstract instances - in a structured and consistent way. This is especially useful for symbolic interpreters, type systems, or metaprogramming tasks where you need clear semantics of identity and equality for runtime terms.

Classes

Wrapper What it Represents Comparison Semantics
Module Python module objects By module instance
Class Python class/type objects By class instance
Function Python function or built-in function By function instance
Constant Immutable primitive values By value
AbstractInstance Abstract instance of a class (not a real object) By identity (each AbstractInstance is unique)

Usage

from python_runtime_entity_wrappers import Module, Class, Function, Constant, AbstractInstance

import math

# Module: refers to the 'math' module object
m1 = Module(math)
m2 = Module(math)
assert m1 == m2


# Class: refers to a Python class
class MyClass: pass


c1 = Class(MyClass)
c2 = Class(MyClass)
assert c1 == c2


# Function: refers to a Python function
def foo(): return 42


f1 = Function(foo)
f2 = Function(foo)
assert f1 == f2

# Constant: refers to a literal/primitive value
k1 = Constant(123)
k2 = Constant(123)
assert k1 == k2

# AbstractInstance: refers to an *abstract* instance of a class (not a real Python object)
i1 = AbstractInstance(MyClass)
i2 = AbstractInstance(MyClass)
assert i1 != i2  # Each AbstractInstance(...) is unique (identity equality)

Contributing

Contributions are welcome! Please submit pull requests or open issues on the GitHub repository.

License

This project is licensed under the MIT License.

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_runtime_entity_wrappers-0.1.0a0.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

python_runtime_entity_wrappers-0.1.0a0-py2.py3-none-any.whl (4.4 kB view details)

Uploaded Python 2Python 3

File details

Details for the file python_runtime_entity_wrappers-0.1.0a0.tar.gz.

File metadata

File hashes

Hashes for python_runtime_entity_wrappers-0.1.0a0.tar.gz
Algorithm Hash digest
SHA256 4697579673c3210cbdb89191df8f28eab52d839e675472b83642d776e171467c
MD5 84cfb00446bab52259765b2acbcb903d
BLAKE2b-256 7c06a71a4df9b706ef2e324bc1e7887e2773bb2395924e5dd4a40b008b0d4823

See more details on using hashes here.

File details

Details for the file python_runtime_entity_wrappers-0.1.0a0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for python_runtime_entity_wrappers-0.1.0a0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 0692b18cd8741c91e3083271ad50ea33c0a09b1a67cb680cbb05df577def104c
MD5 13e92436a47640a52cb236f17768ae07
BLAKE2b-256 eeff1574eebe59efee0718e69c24cb65404b020ab355166cf79ab368b93ffa65

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page