pyrefly-shape-extensions 1.3.2__tar.gz → 1.4.0__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.
- pyrefly_shape_extensions-1.4.0/PKG-INFO +88 -0
- pyrefly_shape_extensions-1.4.0/README.md +52 -0
- {pyrefly_shape_extensions-1.3.2 → pyrefly_shape_extensions-1.4.0}/pyproject.toml +2 -2
- pyrefly_shape_extensions-1.4.0/shape_extensions/__init__.py +752 -0
- {pyrefly_shape_extensions-1.3.2 → pyrefly_shape_extensions-1.4.0}/shape_extensions/dsl.py +39 -0
- pyrefly_shape_extensions-1.3.2/PKG-INFO +0 -47
- pyrefly_shape_extensions-1.3.2/README.md +0 -11
- pyrefly_shape_extensions-1.3.2/shape_extensions/__init__.py +0 -438
- {pyrefly_shape_extensions-1.3.2 → pyrefly_shape_extensions-1.4.0}/LICENSE +0 -0
- {pyrefly_shape_extensions-1.3.2 → pyrefly_shape_extensions-1.4.0}/shape_extensions/py.typed +0 -0
- {pyrefly_shape_extensions-1.3.2 → pyrefly_shape_extensions-1.4.0}/shape_extensions/torchscript.py +0 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: pyrefly-shape-extensions
|
|
3
|
+
Version: 1.4.0
|
|
4
|
+
Summary: Shape typing primitives and DSL for Pyrefly tensor shape tracking
|
|
5
|
+
Project-URL: homepage, https://pyrefly.org
|
|
6
|
+
Project-URL: documentation, https://pyrefly.org/en/docs/
|
|
7
|
+
License: MIT License
|
|
8
|
+
|
|
9
|
+
Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
10
|
+
|
|
11
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
12
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
13
|
+
in the Software without restriction, including without limitation the rights
|
|
14
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
15
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
16
|
+
furnished to do so, subject to the following conditions:
|
|
17
|
+
|
|
18
|
+
The above copyright notice and this permission notice shall be included in all
|
|
19
|
+
copies or substantial portions of the Software.
|
|
20
|
+
|
|
21
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
22
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
23
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
24
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
25
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
26
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
27
|
+
SOFTWARE.
|
|
28
|
+
License-File: LICENSE
|
|
29
|
+
Keywords: pyrefly,shapes,tensor,typechecker,typechecking
|
|
30
|
+
Classifier: Development Status :: 4 - Beta
|
|
31
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
32
|
+
Classifier: Programming Language :: Python
|
|
33
|
+
Classifier: Programming Language :: Python :: 3
|
|
34
|
+
Requires-Python: >=3.10
|
|
35
|
+
Description-Content-Type: text/markdown
|
|
36
|
+
|
|
37
|
+
# pyrefly-shape-extensions
|
|
38
|
+
|
|
39
|
+
Runtime helpers for Pyrefly tensor shape annotations.
|
|
40
|
+
|
|
41
|
+
This package provides the lightweight `shape_extensions` module used by
|
|
42
|
+
Pyrefly's tensor shape stubs. It defines runtime no-op versions of the shape
|
|
43
|
+
typing primitives so annotations such as `Tensor[[B, T]]`, `IntVar("B")`, and
|
|
44
|
+
`assert_shape(x.shape, (2, 3))` can be evaluated by Python while Pyrefly uses the
|
|
45
|
+
corresponding stubs for static shape checking.
|
|
46
|
+
|
|
47
|
+
`NamedInts` and `CaptureNamedInts` carry named axis lengths from `**kwargs`
|
|
48
|
+
into shape rules for einops-like APIs.
|
|
49
|
+
|
|
50
|
+
`RegularNestedList[Shape, Domain]` represents regular (non-jagged) nested list
|
|
51
|
+
literals; for example, `[[1, 2], [3, 4]]` binds `Shape` to `[2, 2]`. Unsupported
|
|
52
|
+
containers and irregular literals use ordinary typing and any fallback overload
|
|
53
|
+
supplied by the consumer.
|
|
54
|
+
|
|
55
|
+
`IntTupleOrList[Values]` is a stub-authoring parameter type for APIs that accept
|
|
56
|
+
integer tuples and lists. A direct, unstarred list literal such as `[2, 3]`
|
|
57
|
+
binds `Values` to `IntTuple[2, 3]`; an existing or starred list remains gradual,
|
|
58
|
+
while a direct literal containing a non-integer is rejected.
|
|
59
|
+
|
|
60
|
+
The package is versioned in lockstep with Pyrefly.
|
|
61
|
+
|
|
62
|
+
## Portable shape annotations
|
|
63
|
+
|
|
64
|
+
`Shaped[T, "..."]` is an alias for `typing.Annotated`, so other type checkers
|
|
65
|
+
read `T` and ignore the shape string. Inside a `@shape_vars` function or class,
|
|
66
|
+
Pyrefly also reads the string in annotations, casts, type aliases, and class
|
|
67
|
+
bases. Use `@shape_vars("")` for a literal shape with no declared dimensions.
|
|
68
|
+
|
|
69
|
+
Legacy type aliases cannot capture dimensions declared on an enclosing
|
|
70
|
+
`@shape_vars` function or class. For example, an `Alias: TypeAlias =
|
|
71
|
+
Shaped[Array, "[N]"]` inside a `@shape_vars("N")` definition reports that `N`
|
|
72
|
+
is not in scope for the alias. This is the same restriction that applies when
|
|
73
|
+
legacy type aliases capture ordinary enclosing type parameters. Use the
|
|
74
|
+
`Shaped` annotation directly in that scope; literal-only aliases are supported.
|
|
75
|
+
|
|
76
|
+
A defaulted `@shape_vars("N")` dimension after a `*Ts` class parameter is not
|
|
77
|
+
supported: Pyrefly reports the declaration and can mistake a trailing ordinary
|
|
78
|
+
type argument for the dimension. Pyrefly accepts
|
|
79
|
+
`@shape_vars("N", required=True) class Required[*Ts]` with an explicit shape,
|
|
80
|
+
as in `Required[int, str, 3]`; `Required[int, str]` still treats `str` as a
|
|
81
|
+
dimension. This explicit specialization is specific to Pyrefly, not a
|
|
82
|
+
portable workaround for other type checkers.
|
|
83
|
+
|
|
84
|
+
At runtime, `Shaped[Base, "..."]` can appear as a class base because
|
|
85
|
+
`Annotated` resolves to `Base`. Pyrefly reads its shape. In Pyright 1.1.414,
|
|
86
|
+
the base is rejected and inherited attributes and methods are inferred as
|
|
87
|
+
`Unknown` downstream. Do not rely on this base spelling when Pyright users
|
|
88
|
+
need inherited signatures.
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# pyrefly-shape-extensions
|
|
2
|
+
|
|
3
|
+
Runtime helpers for Pyrefly tensor shape annotations.
|
|
4
|
+
|
|
5
|
+
This package provides the lightweight `shape_extensions` module used by
|
|
6
|
+
Pyrefly's tensor shape stubs. It defines runtime no-op versions of the shape
|
|
7
|
+
typing primitives so annotations such as `Tensor[[B, T]]`, `IntVar("B")`, and
|
|
8
|
+
`assert_shape(x.shape, (2, 3))` can be evaluated by Python while Pyrefly uses the
|
|
9
|
+
corresponding stubs for static shape checking.
|
|
10
|
+
|
|
11
|
+
`NamedInts` and `CaptureNamedInts` carry named axis lengths from `**kwargs`
|
|
12
|
+
into shape rules for einops-like APIs.
|
|
13
|
+
|
|
14
|
+
`RegularNestedList[Shape, Domain]` represents regular (non-jagged) nested list
|
|
15
|
+
literals; for example, `[[1, 2], [3, 4]]` binds `Shape` to `[2, 2]`. Unsupported
|
|
16
|
+
containers and irregular literals use ordinary typing and any fallback overload
|
|
17
|
+
supplied by the consumer.
|
|
18
|
+
|
|
19
|
+
`IntTupleOrList[Values]` is a stub-authoring parameter type for APIs that accept
|
|
20
|
+
integer tuples and lists. A direct, unstarred list literal such as `[2, 3]`
|
|
21
|
+
binds `Values` to `IntTuple[2, 3]`; an existing or starred list remains gradual,
|
|
22
|
+
while a direct literal containing a non-integer is rejected.
|
|
23
|
+
|
|
24
|
+
The package is versioned in lockstep with Pyrefly.
|
|
25
|
+
|
|
26
|
+
## Portable shape annotations
|
|
27
|
+
|
|
28
|
+
`Shaped[T, "..."]` is an alias for `typing.Annotated`, so other type checkers
|
|
29
|
+
read `T` and ignore the shape string. Inside a `@shape_vars` function or class,
|
|
30
|
+
Pyrefly also reads the string in annotations, casts, type aliases, and class
|
|
31
|
+
bases. Use `@shape_vars("")` for a literal shape with no declared dimensions.
|
|
32
|
+
|
|
33
|
+
Legacy type aliases cannot capture dimensions declared on an enclosing
|
|
34
|
+
`@shape_vars` function or class. For example, an `Alias: TypeAlias =
|
|
35
|
+
Shaped[Array, "[N]"]` inside a `@shape_vars("N")` definition reports that `N`
|
|
36
|
+
is not in scope for the alias. This is the same restriction that applies when
|
|
37
|
+
legacy type aliases capture ordinary enclosing type parameters. Use the
|
|
38
|
+
`Shaped` annotation directly in that scope; literal-only aliases are supported.
|
|
39
|
+
|
|
40
|
+
A defaulted `@shape_vars("N")` dimension after a `*Ts` class parameter is not
|
|
41
|
+
supported: Pyrefly reports the declaration and can mistake a trailing ordinary
|
|
42
|
+
type argument for the dimension. Pyrefly accepts
|
|
43
|
+
`@shape_vars("N", required=True) class Required[*Ts]` with an explicit shape,
|
|
44
|
+
as in `Required[int, str, 3]`; `Required[int, str]` still treats `str` as a
|
|
45
|
+
dimension. This explicit specialization is specific to Pyrefly, not a
|
|
46
|
+
portable workaround for other type checkers.
|
|
47
|
+
|
|
48
|
+
At runtime, `Shaped[Base, "..."]` can appear as a class base because
|
|
49
|
+
`Annotated` resolves to `Base`. Pyrefly reads its shape. In Pyright 1.1.414,
|
|
50
|
+
the base is rejected and inherited attributes and methods are inferred as
|
|
51
|
+
`Unknown` downstream. Do not rely on this base spelling when Pyright users
|
|
52
|
+
need inherited signatures.
|
|
@@ -6,9 +6,9 @@ build-backend = "hatchling.build"
|
|
|
6
6
|
name = "pyrefly-shape-extensions"
|
|
7
7
|
description = "Shape typing primitives and DSL for Pyrefly tensor shape tracking"
|
|
8
8
|
readme = "README.md"
|
|
9
|
-
requires-python = ">=3.
|
|
9
|
+
requires-python = ">=3.10"
|
|
10
10
|
license = { file = "LICENSE" }
|
|
11
|
-
version = "1.
|
|
11
|
+
version = "1.4.0"
|
|
12
12
|
keywords = ["typechecker", "typechecking", "shapes", "tensor", "pyrefly"]
|
|
13
13
|
classifiers = [
|
|
14
14
|
"Development Status :: 4 - Beta",
|