type-python 0.1.1__py3-none-win_amd64.whl → 0.3.0__py3-none-win_amd64.whl

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.
@@ -0,0 +1,118 @@
1
+ Metadata-Version: 2.4
2
+ Name: type-python
3
+ Version: 0.3.0
4
+ Summary: A statically-typed authoring language that compiles to standard Python
5
+ Author: unadlib
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/type-python/type-python
8
+ Project-URL: Repository, https://github.com/type-python/type-python
9
+ Project-URL: Documentation, https://github.com/type-python/type-python/tree/main/docs
10
+ Project-URL: Issues, https://github.com/type-python/type-python/issues
11
+ Keywords: typepython,type-checking,compiler,python,static-typing
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.9
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Rust
20
+ Classifier: Topic :: Software Development :: Compilers
21
+ Classifier: Topic :: Software Development :: Quality Assurance
22
+ Classifier: Typing :: Typed
23
+ Requires-Python: >=3.9
24
+ Description-Content-Type: text/markdown
25
+ License-File: LICENSE
26
+ Dynamic: license-file
27
+
28
+ <p align="center">
29
+ <img src="https://raw.githubusercontent.com/type-python/type-python/main/logo.png" alt="TypePython" width="128" />
30
+ </p>
31
+
32
+ <h1 align="center">TypePython</h1>
33
+
34
+ <p align="center">
35
+ <strong>Write richer types. Emit standard Python.</strong>
36
+ </p>
37
+
38
+ ---
39
+
40
+ A statically-typed authoring language that compiles to standard Python.
41
+
42
+ Write `.tpy` source files with `interface`, `data class`, `sealed class`, inline generics, and strict null safety. The compiler emits standard `.py` + `.pyi` files for Python 3.10-3.14. No custom runtime, no vendor lock-in.
43
+
44
+ ## Install
45
+
46
+ ```bash
47
+ pip install type-python
48
+ typepython --help
49
+ ```
50
+
51
+ The Python package bridge supports **Python 3.9+**. Generated projects can target **Python 3.10 through 3.14**.
52
+
53
+ Published wheels bundle the Rust CLI binary. Prebuilt wheels are available for Windows AMD64, macOS x86_64, macOS arm64, and Linux x86_64. Other platforms fall back to the source distribution and require Rust + `cargo`.
54
+
55
+ ## Quick Start
56
+
57
+ ```bash
58
+ typepython init --dir my-project
59
+ cd my-project
60
+ typepython check --project .
61
+ typepython build --project .
62
+ ```
63
+
64
+ Example source:
65
+
66
+ ```python
67
+ # src/app/__init__.tpy
68
+
69
+ sealed class Expr:
70
+ pass
71
+
72
+ data class Num(Expr):
73
+ value: int
74
+
75
+ data class Add(Expr):
76
+ left: Expr
77
+ right: Expr
78
+
79
+ def evaluate(expr: Expr) -> int:
80
+ match expr:
81
+ case Num(value=v):
82
+ return v
83
+ case Add(left=l, right=r):
84
+ return evaluate(l) + evaluate(r)
85
+ # Compiler proves all cases are covered -- no default needed.
86
+ ```
87
+
88
+ ## What You Get
89
+
90
+ | Your code (`.tpy`) | Emitted output (`.py` / `.pyi`) |
91
+ | --------------------------------- | -------------------------------------------------- |
92
+ | `sealed class Expr:` | `class Expr: # tpy:sealed` |
93
+ | `data class Num(Expr):` | `@dataclass` plus ordinary `class Num(Expr):` |
94
+ | `interface Drawable:` | `class Drawable(Protocol):` |
95
+ | `overload def f(x: int) -> int:` | `@overload` plus ordinary `def f(x: int) -> int:` |
96
+ | `typealias Pair[T] = tuple[T, T]` | `T = TypeVar("T"); Pair: TypeAlias = tuple[T, T]` |
97
+
98
+ - **Rich type system** -- `unknown`, `dynamic`, `Never`, strict nulls, sealed exhaustiveness, generic defaults, TypeVarTuple
99
+ - **TypedDict utilities** -- `Partial`, `Required_`, `Readonly`, `Mutable`, `Pick`, `Omit`
100
+ - **Full toolchain** -- `init`, `check`, `build`, `watch`, `clean`, `verify`, `lsp`, `migrate`
101
+ - **LSP server** -- hover, go-to-definition, references, rename, completions, signature help, diagnostics
102
+ - **Standard output** -- emitted `.py` + `.pyi` work with mypy, pyright, and ty out of the box
103
+
104
+ ## Documentation
105
+
106
+ - [Getting Started](https://github.com/type-python/type-python/blob/main/docs/getting-started.md)
107
+ - [Syntax Guide](https://github.com/type-python/type-python/blob/main/docs/syntax-guide.md)
108
+ - [Type System](https://github.com/type-python/type-python/blob/main/docs/type-system.md)
109
+ - [Configuration](https://github.com/type-python/type-python/blob/main/docs/configuration.md)
110
+ - [CLI Reference](https://github.com/type-python/type-python/blob/main/docs/cli-reference.md)
111
+ - [Interoperability](https://github.com/type-python/type-python/blob/main/docs/interop.md)
112
+ - [Language Spec](https://github.com/type-python/type-python/blob/main/docs/spec/language-spec-v1.md)
113
+
114
+ ## Links
115
+
116
+ - [Repository](https://github.com/type-python/type-python)
117
+ - [Issues](https://github.com/type-python/type-python/issues)
118
+ - [License (MIT)](https://github.com/type-python/type-python/blob/main/LICENSE)
@@ -0,0 +1,11 @@
1
+ type_python-0.3.0.dist-info/licenses/LICENSE,sha256=BMHUZ3id_LOrEdv_GmAbL1ttlKsqjZz14f1_M1tn73k,1089
2
+ typepython/__init__.py,sha256=j68Z_JZemkGBrmytvTfDu3VOUxN8C5Ajo7ZEpVt1gxY,308
3
+ typepython/__main__.py,sha256=m8cggQyLAOSPtb8r-uUv_g53whMoPXtF2NX9yLuPyLg,89
4
+ typepython/_runner.py,sha256=DySWPTud0FIAv2-0xhmwAyt_kk3w3kFJWK8FcYSe858,1777
5
+ typepython/annotation_compat.py,sha256=VKUJEAj9NdDWr1j5cB2OIWlupmDyWVYvQkpJ2Jer2m8,4223
6
+ typepython/bin/typepython.exe,sha256=TaX26_INBP-1J0PyIAIBlY3tAtKHiPppnUdH0HpJh0o,11883008
7
+ type_python-0.3.0.dist-info/METADATA,sha256=YuEUMYng1t8GVUNRkFlbaIznUDQm44k4-CdksuxHLEc,4864
8
+ type_python-0.3.0.dist-info/WHEEL,sha256=GjDPPQwEcripVP6P2r3RxLa-h5Lb9ifGB7FYYtbLDT0,98
9
+ type_python-0.3.0.dist-info/entry_points.txt,sha256=B5Yjdi-RWaeRy7YUcni1lU_ya2lVZXM8llSFNSKEq0U,56
10
+ type_python-0.3.0.dist-info/top_level.txt,sha256=JFRFjt3AXvRQ99SKMxUVu9e3TOp2QpspvE-jk85uMjU,11
11
+ type_python-0.3.0.dist-info/RECORD,,
typepython/__init__.py CHANGED
@@ -1,5 +1,13 @@
1
1
  from ._runner import main
2
+ from .annotation_compat import AnnotationFormat, AnnotationSupport, get_annotations, supported_formats
2
3
 
3
- __all__ = ["__version__", "main"]
4
+ __all__ = [
5
+ "__version__",
6
+ "AnnotationFormat",
7
+ "AnnotationSupport",
8
+ "get_annotations",
9
+ "main",
10
+ "supported_formats",
11
+ ]
4
12
 
5
- __version__ = "0.1.1"
13
+ __version__ = "0.3.0"
@@ -0,0 +1,142 @@
1
+ from __future__ import annotations
2
+
3
+ import inspect
4
+ import sys
5
+ from dataclasses import dataclass
6
+ from enum import Enum
7
+ from types import ModuleType
8
+ from typing import Any
9
+
10
+ try:
11
+ import annotationlib as _annotationlib
12
+ except ImportError: # pragma: no cover - exercised on pre-3.14 hosts
13
+ _annotationlib = None
14
+
15
+ HAS_ANNOTATIONLIB = _annotationlib is not None
16
+
17
+
18
+ class AnnotationFormat(str, Enum):
19
+ VALUE = "value"
20
+ FORWARDREF = "forwardref"
21
+ STRING = "string"
22
+
23
+
24
+ @dataclass(frozen=True)
25
+ class AnnotationSupport:
26
+ value: bool
27
+ forwardref: bool
28
+ string: bool
29
+
30
+
31
+ def supported_formats() -> AnnotationSupport:
32
+ if HAS_ANNOTATIONLIB:
33
+ return AnnotationSupport(value=True, forwardref=True, string=True)
34
+ return AnnotationSupport(value=True, forwardref=False, string=False)
35
+
36
+
37
+ def get_annotations(
38
+ obj: Any,
39
+ *,
40
+ globals: dict[str, Any] | None = None,
41
+ locals: dict[str, Any] | None = None,
42
+ eval_str: bool = False,
43
+ format: AnnotationFormat | str = AnnotationFormat.VALUE,
44
+ ) -> dict[str, Any]:
45
+ normalized = _normalize_format(format)
46
+ if HAS_ANNOTATIONLIB:
47
+ return _annotationlib.get_annotations(
48
+ obj,
49
+ globals=globals,
50
+ locals=locals,
51
+ eval_str=eval_str,
52
+ format=_annotationlib_format(normalized),
53
+ )
54
+ if normalized is not AnnotationFormat.VALUE:
55
+ raise NotImplementedError(
56
+ "annotation formats other than VALUE require Python 3.14+ annotationlib"
57
+ )
58
+ return _fallback_get_annotations(
59
+ obj,
60
+ globals=globals,
61
+ locals=locals,
62
+ eval_str=eval_str,
63
+ )
64
+
65
+
66
+ def _normalize_format(format: AnnotationFormat | str) -> AnnotationFormat:
67
+ if isinstance(format, AnnotationFormat):
68
+ return format
69
+ return AnnotationFormat(format)
70
+
71
+
72
+ def _annotationlib_format(format: AnnotationFormat) -> Any:
73
+ assert _annotationlib is not None
74
+ if format is AnnotationFormat.VALUE:
75
+ return _annotationlib.Format.VALUE
76
+ if format is AnnotationFormat.FORWARDREF:
77
+ return _annotationlib.Format.FORWARDREF
78
+ return _annotationlib.Format.STRING
79
+
80
+
81
+ def _fallback_get_annotations(
82
+ obj: Any,
83
+ *,
84
+ globals: dict[str, Any] | None,
85
+ locals: dict[str, Any] | None,
86
+ eval_str: bool,
87
+ ) -> dict[str, Any]:
88
+ if hasattr(inspect, "get_annotations"):
89
+ return inspect.get_annotations(
90
+ obj,
91
+ globals=globals,
92
+ locals=locals,
93
+ eval_str=eval_str,
94
+ )
95
+
96
+ raw = _legacy_raw_annotations(obj)
97
+ if raw is None:
98
+ return {}
99
+ annotations = dict(raw)
100
+ if not eval_str:
101
+ return annotations
102
+
103
+ globalns, localns = _legacy_eval_namespaces(obj, globals, locals)
104
+ evaluated: dict[str, Any] = {}
105
+ for name, value in annotations.items():
106
+ if isinstance(value, str):
107
+ evaluated[name] = eval(value, globalns, localns)
108
+ else:
109
+ evaluated[name] = value
110
+ return evaluated
111
+
112
+
113
+ def _legacy_raw_annotations(obj: Any) -> dict[str, Any] | None:
114
+ if isinstance(obj, type):
115
+ return obj.__dict__.get("__annotations__")
116
+ if isinstance(obj, ModuleType):
117
+ return getattr(obj, "__annotations__", None)
118
+ return getattr(obj, "__annotations__", None)
119
+
120
+
121
+ def _legacy_eval_namespaces(
122
+ obj: Any,
123
+ globals: dict[str, Any] | None,
124
+ locals: dict[str, Any] | None,
125
+ ) -> tuple[dict[str, Any], dict[str, Any]]:
126
+ if globals is not None or locals is not None:
127
+ return globals or {}, locals or globals or {}
128
+
129
+ if isinstance(obj, ModuleType):
130
+ namespace = vars(obj)
131
+ return namespace, namespace
132
+ if isinstance(obj, type):
133
+ module = sys.modules.get(getattr(obj, "__module__", ""))
134
+ globalns = vars(module) if module is not None else {}
135
+ return globalns, dict(vars(obj))
136
+
137
+ globalns = getattr(obj, "__globals__", None)
138
+ if globalns is not None:
139
+ return globalns, globalns
140
+ module = sys.modules.get(getattr(obj, "__module__", ""))
141
+ namespace = vars(module) if module is not None else {}
142
+ return namespace, namespace
Binary file
@@ -1,98 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: type-python
3
- Version: 0.1.1
4
- Summary: A statically-typed authoring language that compiles to standard Python
5
- Author: unadlib
6
- License-Expression: MIT
7
- Project-URL: Homepage, https://github.com/type-python/type-python
8
- Project-URL: Repository, https://github.com/type-python/type-python
9
- Project-URL: Documentation, https://github.com/type-python/type-python/tree/main/docs
10
- Project-URL: Issues, https://github.com/type-python/type-python/issues
11
- Keywords: typepython,type-checking,compiler,python,static-typing
12
- Classifier: Development Status :: 3 - Alpha
13
- Classifier: Intended Audience :: Developers
14
- Classifier: Programming Language :: Python :: 3
15
- Classifier: Programming Language :: Python :: 3.9
16
- Classifier: Programming Language :: Python :: 3.10
17
- Classifier: Programming Language :: Python :: 3.11
18
- Classifier: Programming Language :: Python :: 3.12
19
- Classifier: Programming Language :: Rust
20
- Classifier: Topic :: Software Development :: Compilers
21
- Classifier: Topic :: Software Development :: Quality Assurance
22
- Classifier: Typing :: Typed
23
- Requires-Python: >=3.9
24
- Description-Content-Type: text/markdown
25
- License-File: LICENSE
26
- Dynamic: license-file
27
-
28
- # TypePython
29
-
30
- **A statically-typed authoring language that compiles to standard Python.**
31
-
32
- TypePython lets you write `.tpy` source files with features such as `interface`, `data class`, `sealed class`, inline generics, and strict null safety. The compiler emits standard `.py` and `.pyi` files that run on ordinary Python interpreters and type-check with mypy or pyright.
33
-
34
- ## Install
35
-
36
- ```bash
37
- pip install type-python
38
- typepython --help
39
- ```
40
-
41
- Published wheels are platform-specific because they bundle the Rust CLI binary. Supported releases publish prebuilt wheels for Windows AMD64, macOS x86_64, macOS arm64, and Linux x86_64, so those platforms can install and run TypePython without Rust. Other platforms fall back to the source distribution and require a Rust toolchain with `cargo`.
42
-
43
- The Python package bridge supports Python 3.9+. Generated TypePython projects currently target Python 3.10, 3.11, or 3.12.
44
-
45
- ## Quick Start
46
-
47
- Create a project:
48
-
49
- ```bash
50
- typepython init --dir my-project
51
- cd my-project
52
- typepython check --project .
53
- typepython build --project .
54
- ```
55
-
56
- Example source:
57
-
58
- ```python
59
- sealed class Expr:
60
- pass
61
-
62
- data class Num(Expr):
63
- value: int
64
-
65
- data class Add(Expr):
66
- left: Expr
67
- right: Expr
68
-
69
- def evaluate(expr: Expr) -> int:
70
- match expr:
71
- case Num(value=v):
72
- return v
73
- case Add(left=l, right=r):
74
- return evaluate(l) + evaluate(r)
75
- ```
76
-
77
- ## What You Get
78
-
79
- - Standard `.py` and `.pyi` output with no custom runtime
80
- - Type system features such as `unknown`, strict nulls, sealed exhaustiveness, `TypedDict` utilities, and generic defaults
81
- - CLI commands for `init`, `check`, `build`, `watch`, `clean`, `verify`, `lsp`, and `migrate`
82
- - Interoperability with standard Python typing tools and package publishing workflows
83
-
84
- ## Documentation
85
-
86
- - Getting started: <https://github.com/type-python/type-python/blob/main/docs/getting-started.md>
87
- - Syntax guide: <https://github.com/type-python/type-python/blob/main/docs/syntax-guide.md>
88
- - Type system: <https://github.com/type-python/type-python/blob/main/docs/type-system.md>
89
- - Configuration: <https://github.com/type-python/type-python/blob/main/docs/configuration.md>
90
- - CLI reference: <https://github.com/type-python/type-python/blob/main/docs/cli-reference.md>
91
- - Interoperability: <https://github.com/type-python/type-python/blob/main/docs/interop.md>
92
- - Language spec: <https://github.com/type-python/type-python/blob/main/docs/spec/language-spec-v1.md>
93
-
94
- ## Project Links
95
-
96
- - Repository: <https://github.com/type-python/type-python>
97
- - Issues: <https://github.com/type-python/type-python/issues>
98
- - License: <https://github.com/type-python/type-python/blob/main/LICENSE>
@@ -1,10 +0,0 @@
1
- type_python-0.1.1.dist-info/licenses/LICENSE,sha256=BMHUZ3id_LOrEdv_GmAbL1ttlKsqjZz14f1_M1tn73k,1089
2
- typepython/__init__.py,sha256=NUOU0aHfeQ0sJOQ9yDxz7NUqrOUpkzSNOMvQWFWRgtg,89
3
- typepython/__main__.py,sha256=m8cggQyLAOSPtb8r-uUv_g53whMoPXtF2NX9yLuPyLg,89
4
- typepython/_runner.py,sha256=DySWPTud0FIAv2-0xhmwAyt_kk3w3kFJWK8FcYSe858,1777
5
- typepython/bin/typepython.exe,sha256=iAUB49_o9uEKjhnfZuxiu5BeZghI8VVMDAcysevnOh0,11033088
6
- type_python-0.1.1.dist-info/METADATA,sha256=EtMZV3WeDxhBZtB5ydwyn1xm3MtYMZ7iSmnWlwFtAo4,3930
7
- type_python-0.1.1.dist-info/WHEEL,sha256=GjDPPQwEcripVP6P2r3RxLa-h5Lb9ifGB7FYYtbLDT0,98
8
- type_python-0.1.1.dist-info/entry_points.txt,sha256=B5Yjdi-RWaeRy7YUcni1lU_ya2lVZXM8llSFNSKEq0U,56
9
- type_python-0.1.1.dist-info/top_level.txt,sha256=JFRFjt3AXvRQ99SKMxUVu9e3TOp2QpspvE-jk85uMjU,11
10
- type_python-0.1.1.dist-info/RECORD,,