langex 0.1.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- langex-0.1.2/LICENSE +21 -0
- langex-0.1.2/LangEx.egg-info/PKG-INFO +8 -0
- langex-0.1.2/LangEx.egg-info/SOURCES.txt +23 -0
- langex-0.1.2/LangEx.egg-info/dependency_links.txt +1 -0
- langex-0.1.2/LangEx.egg-info/entry_points.txt +2 -0
- langex-0.1.2/LangEx.egg-info/top_level.txt +1 -0
- langex-0.1.2/PKG-INFO +8 -0
- langex-0.1.2/README.md +94 -0
- langex-0.1.2/langex/__init__.py +2 -0
- langex-0.1.2/langex/__main__.py +2 -0
- langex-0.1.2/langex/core/__init__.py +2 -0
- langex-0.1.2/langex/core/callable_meta.py +45 -0
- langex-0.1.2/langex/core/class_meta.py +9 -0
- langex-0.1.2/langex/core/meta.py +14 -0
- langex-0.1.2/langex/core/object_meta.py +7 -0
- langex-0.1.2/langex/core/use.py +19 -0
- langex-0.1.2/langex/immediate.py +7 -0
- langex-0.1.2/langex/interface.py +92 -0
- langex-0.1.2/pyproject.toml +19 -0
- langex-0.1.2/setup.cfg +4 -0
langex-0.1.2/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 AttAditya
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
LangEx.egg-info/PKG-INFO
|
|
5
|
+
LangEx.egg-info/SOURCES.txt
|
|
6
|
+
LangEx.egg-info/dependency_links.txt
|
|
7
|
+
LangEx.egg-info/entry_points.txt
|
|
8
|
+
LangEx.egg-info/top_level.txt
|
|
9
|
+
langex/__init__.py
|
|
10
|
+
langex/__main__.py
|
|
11
|
+
langex/immediate.py
|
|
12
|
+
langex/interface.py
|
|
13
|
+
langex.egg-info/PKG-INFO
|
|
14
|
+
langex.egg-info/SOURCES.txt
|
|
15
|
+
langex.egg-info/dependency_links.txt
|
|
16
|
+
langex.egg-info/entry_points.txt
|
|
17
|
+
langex.egg-info/top_level.txt
|
|
18
|
+
langex/core/__init__.py
|
|
19
|
+
langex/core/callable_meta.py
|
|
20
|
+
langex/core/class_meta.py
|
|
21
|
+
langex/core/meta.py
|
|
22
|
+
langex/core/object_meta.py
|
|
23
|
+
langex/core/use.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
langex
|
langex-0.1.2/PKG-INFO
ADDED
langex-0.1.2/README.md
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# [LangEx](https://pypi.org/project/langex/)
|
|
2
|
+
|
|
3
|
+
Extended Language Support for Python
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
pip install langex
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## About
|
|
12
|
+
|
|
13
|
+
LangEx is an experimental Python library that introduces additional language-level constructs using decorators, metadata inspection, and structural validation. It focuses on enabling capabilities that Python does not strictly enforce by default, such as interface-like behavior and structured object metadata.
|
|
14
|
+
|
|
15
|
+
The project builds small language utilities that operate on Python objects (functions, classes, and other callables) to inspect, validate, and extend their behavior while remaining fully compatible with standard Python.
|
|
16
|
+
|
|
17
|
+
## Features
|
|
18
|
+
- Interface-like constructs for Python classes
|
|
19
|
+
- Metadata extraction for Python objects and callables
|
|
20
|
+
- Runtime validation utilities
|
|
21
|
+
- Decorator-based language extensions
|
|
22
|
+
- Lightweight core inspection tools
|
|
23
|
+
|
|
24
|
+
## Example
|
|
25
|
+
|
|
26
|
+
### Defining an Interface
|
|
27
|
+
|
|
28
|
+
```py
|
|
29
|
+
from langex.interface import interface
|
|
30
|
+
|
|
31
|
+
@interface
|
|
32
|
+
class Repository:
|
|
33
|
+
def save(self, data): ...
|
|
34
|
+
def get(self, id): ...
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Implementing the Interface
|
|
38
|
+
|
|
39
|
+
```py
|
|
40
|
+
from langex.interface import implements
|
|
41
|
+
|
|
42
|
+
@implements(Repository)
|
|
43
|
+
class UserRepository:
|
|
44
|
+
def save(self, data):
|
|
45
|
+
...
|
|
46
|
+
|
|
47
|
+
def get(self, id):
|
|
48
|
+
...
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
If required methods are missing, validation will raise an error.
|
|
52
|
+
|
|
53
|
+
## Project Structure
|
|
54
|
+
|
|
55
|
+
```tree
|
|
56
|
+
langex
|
|
57
|
+
├── __init__.py
|
|
58
|
+
├── __main__.py
|
|
59
|
+
├── immediate.py
|
|
60
|
+
├── interface.py
|
|
61
|
+
├── core
|
|
62
|
+
│ ├── __init__.py
|
|
63
|
+
│ ├── callable_meta.py
|
|
64
|
+
│ ├── class_meta.py
|
|
65
|
+
│ ├── meta.py
|
|
66
|
+
│ ├── object_meta.py
|
|
67
|
+
│ └── use.py
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
The core module provides internal abstractions for inspecting Python objects and extracting structured metadata used by higher-level utilities like interfaces and validations.
|
|
71
|
+
|
|
72
|
+
## Design Philosophy
|
|
73
|
+
|
|
74
|
+
LangEx is designed around a few principles:
|
|
75
|
+
- Pure Python implementation
|
|
76
|
+
- Minimal runtime overhead
|
|
77
|
+
- Explicit developer intent
|
|
78
|
+
- Small composable language utilities
|
|
79
|
+
|
|
80
|
+
Rather than acting as a framework, LangEx provides foundational language tools that can be used to build higher-level abstractions.
|
|
81
|
+
|
|
82
|
+
## Status
|
|
83
|
+
|
|
84
|
+
Experimental and under active development.
|
|
85
|
+
APIs and structure may evolve as the project grows.
|
|
86
|
+
|
|
87
|
+
## Links
|
|
88
|
+
|
|
89
|
+
- [PyPI](https://pypi.org/project/langex/)
|
|
90
|
+
- [GitHub](https://github.com/attaditya/langex)
|
|
91
|
+
- [License](https://github.com/attaditya/langex/tree/main/LICENSE)
|
|
92
|
+
|
|
93
|
+
> _Made with <3 by [AttAditya](https://github.com/AttAditya)_
|
|
94
|
+
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
class _LangexCallableTypehints:
|
|
2
|
+
def __init__(self):
|
|
3
|
+
self.has_typehints = False
|
|
4
|
+
self.has_return_type = False
|
|
5
|
+
self.has_pos_args = False
|
|
6
|
+
self.has_kw_args = False
|
|
7
|
+
self.has_pos_args_list = False
|
|
8
|
+
self.has_kw_args_dict = False
|
|
9
|
+
self.return_type = None
|
|
10
|
+
self.pos_args = []
|
|
11
|
+
self.kw_args = {}
|
|
12
|
+
self.pos_args_list = []
|
|
13
|
+
self.kw_args_dict = {
|
|
14
|
+
"keys": [],
|
|
15
|
+
"values": [],
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
def matches_signature(self, other):
|
|
19
|
+
has_match = [
|
|
20
|
+
self.has_typehints == other.has_typehints,
|
|
21
|
+
self.has_return_type == other.has_return_type,
|
|
22
|
+
self.has_pos_args == other.has_pos_args,
|
|
23
|
+
self.has_kw_args == other.has_kw_args,
|
|
24
|
+
self.has_pos_args_list == other.has_pos_args_list,
|
|
25
|
+
self.has_kw_args_dict == other.has_kw_args_dict,
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
value_match = [
|
|
29
|
+
self.return_type == other.return_type,
|
|
30
|
+
self.pos_args == other.pos_args,
|
|
31
|
+
self.kw_args == other.kw_args,
|
|
32
|
+
self.pos_args_list == other.pos_args_list,
|
|
33
|
+
self.kw_args_dict == other.kw_args_dict,
|
|
34
|
+
]
|
|
35
|
+
|
|
36
|
+
return all(has_match) and all(value_match)
|
|
37
|
+
|
|
38
|
+
class LangexCallableMeta:
|
|
39
|
+
def __init__(self):
|
|
40
|
+
self.typehints = _LangexCallableTypehints()
|
|
41
|
+
|
|
42
|
+
__all__ = [
|
|
43
|
+
"LangexCallableMeta",
|
|
44
|
+
]
|
|
45
|
+
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
from langex.core.callable_meta import LangexCallableMeta
|
|
2
|
+
from langex.core.class_meta import LangexClassMeta
|
|
3
|
+
from langex.core.object_meta import LangexObjectMeta
|
|
4
|
+
|
|
5
|
+
class LangexMeta:
|
|
6
|
+
def __init__(self):
|
|
7
|
+
self.class_meta = LangexClassMeta()
|
|
8
|
+
self.callable_meta = LangexCallableMeta()
|
|
9
|
+
self.object_meta = LangexObjectMeta()
|
|
10
|
+
|
|
11
|
+
__all__ = [
|
|
12
|
+
"LangexMeta",
|
|
13
|
+
]
|
|
14
|
+
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
from langex.core.meta import LangexMeta
|
|
2
|
+
|
|
3
|
+
def use_langex(target):
|
|
4
|
+
if not hasattr(target, "__langex__"):
|
|
5
|
+
setattr(target, "__langex__", LangexMeta())
|
|
6
|
+
|
|
7
|
+
return target
|
|
8
|
+
|
|
9
|
+
def access_langex(target):
|
|
10
|
+
if not hasattr(target, "__langex__"):
|
|
11
|
+
use_langex(target)
|
|
12
|
+
|
|
13
|
+
return target.__langex__
|
|
14
|
+
|
|
15
|
+
__all__ = [
|
|
16
|
+
"use_langex",
|
|
17
|
+
"access_langex",
|
|
18
|
+
]
|
|
19
|
+
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
from langex.core.use import access_langex, use_langex
|
|
2
|
+
from langex.immediate import immediate
|
|
3
|
+
|
|
4
|
+
@immediate
|
|
5
|
+
def _ignored_attributes():
|
|
6
|
+
@use_langex
|
|
7
|
+
class _BlankClass:
|
|
8
|
+
pass
|
|
9
|
+
|
|
10
|
+
return set(dir(_BlankClass))
|
|
11
|
+
|
|
12
|
+
def interface(cls):
|
|
13
|
+
use_langex(cls)
|
|
14
|
+
attributes = set(dir(cls))
|
|
15
|
+
attributes -= _ignored_attributes
|
|
16
|
+
lnx = access_langex(cls)
|
|
17
|
+
class_meta = lnx.class_meta
|
|
18
|
+
class_meta.is_interface = True
|
|
19
|
+
|
|
20
|
+
for attribute_name in attributes:
|
|
21
|
+
attribute = getattr(cls, attribute_name)
|
|
22
|
+
|
|
23
|
+
if not callable(attribute):
|
|
24
|
+
continue
|
|
25
|
+
|
|
26
|
+
callable_lnx = access_langex(attribute)
|
|
27
|
+
typehints = callable_lnx.callable_meta.typehints
|
|
28
|
+
|
|
29
|
+
if typehints.has_typehints:
|
|
30
|
+
class_meta.callables[attribute_name] = callable_lnx
|
|
31
|
+
|
|
32
|
+
def raise_uninstantiable_error(*_, **_____):
|
|
33
|
+
raise TypeError(" ".join([
|
|
34
|
+
f"Class {cls.__name__} is an interface.",
|
|
35
|
+
"It may not be instantiated."
|
|
36
|
+
]))
|
|
37
|
+
|
|
38
|
+
setattr(cls, "__init__", raise_uninstantiable_error)
|
|
39
|
+
|
|
40
|
+
return cls
|
|
41
|
+
|
|
42
|
+
def implements(*interfaces):
|
|
43
|
+
callables = {}
|
|
44
|
+
|
|
45
|
+
for interface in interfaces:
|
|
46
|
+
lnx = access_langex(interface)
|
|
47
|
+
class_meta = lnx.class_meta
|
|
48
|
+
|
|
49
|
+
if not class_meta.is_interface:
|
|
50
|
+
raise TypeError(" ".join([
|
|
51
|
+
f"Class {interface.__name__} is not an interface.",
|
|
52
|
+
"Only interfaces may be implemented."
|
|
53
|
+
]))
|
|
54
|
+
|
|
55
|
+
conflict_callables = set()
|
|
56
|
+
|
|
57
|
+
for callable_name in class_meta.callables:
|
|
58
|
+
if callable_name in callables:
|
|
59
|
+
overiding_callable = class_meta.callables[callable_name]
|
|
60
|
+
existing_callable = callables[callable_name]
|
|
61
|
+
|
|
62
|
+
if not existing_callable.matches_signature(overiding_callable):
|
|
63
|
+
conflict_callables.add(callable_name)
|
|
64
|
+
continue
|
|
65
|
+
|
|
66
|
+
callables[callable_name] = class_meta.callables[callable_name]
|
|
67
|
+
|
|
68
|
+
def decorator(cls):
|
|
69
|
+
unimplemented_methods = callables.keys() - set(dir(cls))
|
|
70
|
+
|
|
71
|
+
if conflict_callables:
|
|
72
|
+
raise TypeError(" ".join([
|
|
73
|
+
f"Class {cls.__name__} has methods that have ",
|
|
74
|
+
"conflicting signatures in interfaces: ",
|
|
75
|
+
", ".join(conflict_callables),
|
|
76
|
+
]))
|
|
77
|
+
|
|
78
|
+
if unimplemented_methods:
|
|
79
|
+
raise NotImplementedError(" ".join([
|
|
80
|
+
f"Class {cls.__name__} does not implement methods:",
|
|
81
|
+
", ".join(unimplemented_methods),
|
|
82
|
+
]))
|
|
83
|
+
|
|
84
|
+
return cls
|
|
85
|
+
|
|
86
|
+
return decorator
|
|
87
|
+
|
|
88
|
+
__all__ = [
|
|
89
|
+
"interface",
|
|
90
|
+
"implements",
|
|
91
|
+
]
|
|
92
|
+
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "langex"
|
|
7
|
+
version = "0.1.2"
|
|
8
|
+
description = "Extended Language Support for Python"
|
|
9
|
+
requires-python = ">=3.14"
|
|
10
|
+
authors = [
|
|
11
|
+
{ name = "AttAditya" }
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
[project.scripts]
|
|
15
|
+
langex = "langex.__main__:main"
|
|
16
|
+
|
|
17
|
+
[tool.setuptools.packages.find]
|
|
18
|
+
where = ["."]
|
|
19
|
+
include = ["langex*"]
|
langex-0.1.2/setup.cfg
ADDED