Metadata-Version: 2.5
Name: pyrefly-shape-extensions
Version: 1.4.0.dev3
Summary: Shape typing primitives and DSL for Pyrefly tensor shape tracking
Project-URL: homepage, https://pyrefly.org
Project-URL: documentation, https://pyrefly.org/en/docs/
License: MIT License
        
        Copyright (c) Meta Platforms, Inc. and affiliates.
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: pyrefly,shapes,tensor,typechecker,typechecking
Classifier: Development Status :: 4 - Beta
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.10
Description-Content-Type: text/markdown

# pyrefly-shape-extensions

Runtime helpers for Pyrefly tensor shape annotations.

This package provides the lightweight `shape_extensions` module used by
Pyrefly's tensor shape stubs. It defines runtime no-op versions of the shape
typing primitives so annotations such as `Tensor[B, T]`, `IntVar("B")`, and
`assert_shape(x.shape, (2, 3))` can be evaluated by Python while Pyrefly uses the
corresponding stubs for static shape checking.

`NamedInts` and `CaptureNamedInts` carry named axis lengths from `**kwargs`
into shape rules for einops-like APIs.

`RegularNestedList[Shape, Domain]` represents regular (non-jagged) nested list
literals; for example, `[[1, 2], [3, 4]]` binds `Shape` to `[2, 2]`. Unsupported
containers and irregular literals use ordinary typing and any fallback overload
supplied by the consumer.

`IntTupleOrList[Values]` is a stub-authoring parameter type for APIs that accept
integer tuples and lists. A direct, unstarred list literal such as `[2, 3]`
binds `Values` to `IntTuple[2, 3]`; an existing or starred list remains gradual,
while a direct literal containing a non-integer is rejected.

The package is versioned in lockstep with Pyrefly.

## Portable shape annotations

`Shaped[T, "..."]` is an alias for `typing.Annotated`, so other type checkers
read `T` and ignore the shape string. Inside a `@shape_vars` function or class,
Pyrefly also reads the string in annotations, casts, type aliases, and class
bases. Use `@shape_vars("")` for a literal shape with no declared dimensions.

Legacy type aliases cannot capture dimensions declared on an enclosing
`@shape_vars` function or class. For example, an `Alias: TypeAlias =
Shaped[Array, "[N]"]` inside a `@shape_vars("N")` definition reports that `N`
is not in scope for the alias. This is the same restriction that applies when
legacy type aliases capture ordinary enclosing type parameters. Use the
`Shaped` annotation directly in that scope; literal-only aliases are supported.

A defaulted `@shape_vars("N")` dimension after a `*Ts` class parameter is not
supported: Pyrefly reports the declaration and can mistake a trailing ordinary
type argument for the dimension. Pyrefly accepts
`@shape_vars("N", required=True) class Required[*Ts]` with an explicit shape,
as in `Required[int, str, 3]`; `Required[int, str]` still treats `str` as a
dimension. This explicit specialization is specific to Pyrefly, not a
portable workaround for other type checkers.

At runtime, `Shaped[Base, "..."]` can appear as a class base because
`Annotated` resolves to `Base`. Pyrefly reads its shape. In Pyright 1.1.414,
the base is rejected and inherited attributes and methods are inferred as
`Unknown` downstream. Do not rely on this base spelling when Pyright users
need inherited signatures.
