mirror of
https://github.com/astral-sh/ty.git
synced 2025-12-23 05:36:53 +00:00
Compare commits
14 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
02351f9fa9 | ||
|
|
d37b7dbd96 | ||
|
|
06b9838404 | ||
|
|
c1e6188b13 | ||
|
|
75d61944b2 | ||
|
|
64f5802668 | ||
|
|
fadfe09665 | ||
|
|
a15bc9c249 | ||
|
|
c9049610b7 | ||
|
|
c0ebde9c99 | ||
|
|
e29c0de224 | ||
|
|
f59fcf3026 | ||
|
|
dac7b7e7ca | ||
|
|
b73aab4d91 |
13 changed files with 1068 additions and 611 deletions
94
CHANGELOG.md
94
CHANGELOG.md
|
|
@ -1,9 +1,103 @@
|
|||
# Changelog
|
||||
|
||||
## 0.0.5
|
||||
|
||||
Released on 2025-12-20.
|
||||
|
||||
### Bug fixes
|
||||
|
||||
- Fix debug-mode server panic when a user typed a class definition by ensuring class arguments are visited in source order for semantic tokens ([#22063](https://github.com/astral-sh/ruff/pull/22063))
|
||||
|
||||
### LSP server
|
||||
|
||||
- Classify docstrings in semantic tokens during syntax highlighting ([#22031](https://github.com/astral-sh/ruff/pull/22031))
|
||||
|
||||
### CLI
|
||||
|
||||
- Add `--force-exclude` option ([#22076](https://github.com/astral-sh/ruff/pull/22076))
|
||||
- Only clear output between two successful checks ([#22078](https://github.com/astral-sh/ruff/pull/22078))
|
||||
|
||||
### Other changes
|
||||
|
||||
- Add support for `dict(...)` calls in `TypedDict` contexts ([#22113](https://github.com/astral-sh/ruff/pull/22113))
|
||||
- Speedup bidirectional type-checking involving large unions by avoiding narrowing on non-generic calls ([#22102](https://github.com/astral-sh/ruff/pull/22102))
|
||||
- Simplify inferred types by avoiding storing multi-inference attempts ([#22062](https://github.com/astral-sh/ruff/pull/22062), [#22103](https://github.com/astral-sh/ruff/pull/22103))
|
||||
- Improve union builder performance ([#22048](https://github.com/astral-sh/ruff/pull/22048))
|
||||
- Only prefer declared types in non-covariant positions ([#22068](https://github.com/astral-sh/ruff/pull/22068))
|
||||
- Respect intersections in iterations ([#21965](https://github.com/astral-sh/ruff/pull/21965))
|
||||
- Sync vendored typeshed stubs ([#22091](https://github.com/astral-sh/ruff/pull/22091)). [Typeshed diff](https://github.com/python/typeshed/compare/ef2b90c67e5c668b91b3ae121baf00ee5165c30b...3c2dbb1fde8e8d1d59b10161c8bf5fd06c0011cd)
|
||||
- Understand that the type of `X` on an enum class will be `int` if `X` is defined using `enum.nonmember` in the class definition ([#22025](https://github.com/astral-sh/ruff/pull/22025))
|
||||
|
||||
### Contributors
|
||||
|
||||
- [@charliermarsh](https://github.com/charliermarsh)
|
||||
- [@ibraheemdev](https://github.com/ibraheemdev)
|
||||
- [@RasmusNygren](https://github.com/RasmusNygren)
|
||||
- [@Hugo-Polloli](https://github.com/Hugo-Polloli)
|
||||
- [@carljm](https://github.com/carljm)
|
||||
- [@Gankra](https://github.com/Gankra)
|
||||
- [@MichaReiser](https://github.com/MichaReiser)
|
||||
|
||||
## 0.0.4
|
||||
|
||||
Released on 2025-12-18.
|
||||
|
||||
### LSP server
|
||||
|
||||
- Add support for attribute docstrings ([#22036](https://github.com/astral-sh/ruff/pull/22036))
|
||||
- Correctly encode multiline tokens for clients not supporting multiline tokens ([#22033](https://github.com/astral-sh/ruff/pull/22033))
|
||||
- Autocompletions: Don't suggest keyword statements when only expressions are valid ([#22002](https://github.com/astral-sh/ruff/pull/22002))
|
||||
- Fix goto-declaration on the right-hand side of `from module import submodule` ([#22042](https://github.com/astral-sh/ruff/pull/22042))
|
||||
- Fix some configuration panics in the LSP ([#22040](https://github.com/astral-sh/ruff/pull/22040))
|
||||
- Gracefully handle client requests that can't be deserialized ([#22051](https://github.com/astral-sh/ruff/pull/22051))
|
||||
|
||||
### Other changes
|
||||
|
||||
- Improve performance for large match statements ([#22045](https://github.com/astral-sh/ruff/pull/22045))
|
||||
- Disable possibly-missing-imports by default ([#22041](https://github.com/astral-sh/ruff/pull/22041))
|
||||
- Implement disjointness for TypedDicts, significantly speeding up checking of code that uses pydantic ([#22044](https://github.com/astral-sh/ruff/pull/22044))
|
||||
|
||||
### Contributors
|
||||
|
||||
- [@oconnor663](https://github.com/oconnor663)
|
||||
- [@MichaReiser](https://github.com/MichaReiser)
|
||||
- [@Gankra](https://github.com/Gankra)
|
||||
- [@RasmusNygren](https://github.com/RasmusNygren)
|
||||
- [@charliermarsh](https://github.com/charliermarsh)
|
||||
|
||||
## 0.0.3
|
||||
|
||||
Released on 2025-12-17.
|
||||
|
||||
### LSP server
|
||||
|
||||
- Improve rendering of signatures in hovers ([#22007](https://github.com/astral-sh/ruff/pull/22007))
|
||||
|
||||
### Core type checking
|
||||
|
||||
- Apply narrowing to `len` calls based on argument size ([#22026](https://github.com/astral-sh/ruff/pull/22026))
|
||||
- Don't add identical lower/upper bounds multiple times when inferring specializations ([#22030](https://github.com/astral-sh/ruff/pull/22030))
|
||||
- Improve `unsupported-base` and `invalid-super-argument` diagnostics to avoid extremely long lines when encountering verbose types ([#22022](https://github.com/astral-sh/ruff/pull/22022))
|
||||
- Improve disambiguation of types in many cases ([#22019](https://github.com/astral-sh/ruff/pull/22019))
|
||||
- Respect deferred values in keyword arguments etc. for `.pyi` files ([#22029](https://github.com/astral-sh/ruff/pull/22029))
|
||||
- Handle field specifier functions that accept `**kwargs` and recognize metaclass-based transformers as instances of `DataclassInstance` ([#22018](https://github.com/astral-sh/ruff/pull/22018))
|
||||
|
||||
### Contributors
|
||||
|
||||
- [@charliermarsh](https://github.com/charliermarsh)
|
||||
- [@sharkdp](https://github.com/sharkdp)
|
||||
- [@Gankra](https://github.com/Gankra)
|
||||
- [@zanieb](https://github.com/zanieb)
|
||||
- [@AlexWaygood](https://github.com/AlexWaygood)
|
||||
- [@dcreager](https://github.com/dcreager)
|
||||
|
||||
## 0.0.2
|
||||
|
||||
Released on 2025-12-16.
|
||||
|
||||
This is the first Beta release of ty, which we're now ready to recommend to motivated users for
|
||||
production use. See our [blog post](https://astral.sh/blog/ty) for more details.
|
||||
|
||||
### LSP server
|
||||
|
||||
- Improve display of completions to show actual insertion text ([#21988](https://github.com/astral-sh/ruff/pull/21988))
|
||||
|
|
|
|||
|
|
@ -47,9 +47,9 @@ To learn more about using ty, see the [documentation](https://docs.astral.sh/ty/
|
|||
|
||||
## Installation
|
||||
|
||||
To install ty, see the [installation](./installation.md) documentation.
|
||||
To install ty, see the [installation](https://docs.astral.sh/ty/installation/) documentation.
|
||||
|
||||
To add the ty language server to your editor, see the [editor integration](./editors.md) guide.
|
||||
To add the ty language server to your editor, see the [editor integration](https://docs.astral.sh/ty/editors/) guide.
|
||||
|
||||
## Getting help
|
||||
|
||||
|
|
@ -73,6 +73,10 @@ See the
|
|||
|
||||
<!-- markdownlint-disable MD001 -->
|
||||
|
||||
#### Why is ty doing \_\_\_\_\_?
|
||||
|
||||
See our [typing FAQ](https://docs.astral.sh/ty/reference/typing-faq).
|
||||
|
||||
#### How do you pronounce ty?
|
||||
|
||||
It's pronounced as "tee - why" ([`/tiː waɪ/`](https://en.wikipedia.org/wiki/Help:IPA/English#Key))
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
[workspace]
|
||||
members = ["cargo:./ruff"]
|
||||
packages = ["ty"]
|
||||
version = "0.0.2"
|
||||
version = "0.0.5"
|
||||
|
||||
# Config for 'dist'
|
||||
[dist]
|
||||
|
|
|
|||
|
|
@ -105,7 +105,7 @@ Starting with version 2025.3, PyCharm users can enable native ty support in the
|
|||
|
||||
1. Select which options should be enabled.
|
||||
|
||||
For more information, refer to [PyCharm documentation](https://www.jetbrains.com/help/pycharm/2025.3/lsp-tools.html#ty).
|
||||
For more information, refer to [PyCharm documentation](https://www.jetbrains.com/help/pycharm/lsp-tools.html#ty).
|
||||
|
||||
## Other editors
|
||||
|
||||
|
|
|
|||
|
|
@ -50,6 +50,72 @@ To update ty, use `uv tool upgrade`:
|
|||
uv tool upgrade ty
|
||||
```
|
||||
|
||||
### Installing with the standalone installer
|
||||
|
||||
ty includes a standalone installer.
|
||||
|
||||
=== "macOS and Linux"
|
||||
|
||||
Use `curl` to download the script and execute it with `sh`:
|
||||
|
||||
```console
|
||||
$ curl -LsSf https://astral.sh/ty/install.sh | sh
|
||||
```
|
||||
|
||||
If your system doesn't have `curl`, you can use `wget`:
|
||||
|
||||
```console
|
||||
$ wget -qO- https://astral.sh/ty/install.sh | sh
|
||||
```
|
||||
|
||||
Request a specific version by including it in the URL:
|
||||
|
||||
```console
|
||||
$ curl -LsSf https://astral.sh/ty/0.0.5/install.sh | sh
|
||||
```
|
||||
|
||||
=== "Windows"
|
||||
|
||||
Use `irm` to download the script and execute it with `iex`:
|
||||
|
||||
```pwsh-session
|
||||
PS> powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/ty/install.ps1 | iex"
|
||||
```
|
||||
|
||||
Changing the [execution policy](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_execution_policies?view=powershell-7.4#powershell-execution-policies) allows running a script from the internet.
|
||||
|
||||
Request a specific version by including it in the URL:
|
||||
|
||||
```pwsh-session
|
||||
PS> powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/ty/0.0.5/install.ps1 | iex"
|
||||
```
|
||||
|
||||
!!! tip
|
||||
|
||||
The installation script may be inspected before use:
|
||||
|
||||
=== "macOS and Linux"
|
||||
|
||||
```console
|
||||
$ curl -LsSf https://astral.sh/ty/install.sh | less
|
||||
```
|
||||
|
||||
=== "Windows"
|
||||
|
||||
```pwsh-session
|
||||
PS> powershell -c "irm https://astral.sh/ty/install.ps1 | more"
|
||||
```
|
||||
|
||||
Alternatively, the installer or binaries can be downloaded directly from [GitHub](#installing-from-github-releases).
|
||||
|
||||
### Installing from GitHub Releases
|
||||
|
||||
ty release artifacts can be downloaded directly from
|
||||
[GitHub Releases](https://github.com/astral-sh/ty/releases).
|
||||
|
||||
Each release page includes binaries for all supported platforms as well as instructions for using
|
||||
the standalone installer via `github.com` instead of `astral.sh`.
|
||||
|
||||
### Installing globally with pipx
|
||||
|
||||
Install ty globally with pipx:
|
||||
|
|
@ -83,7 +149,7 @@ COPY --from=ghcr.io/astral-sh/ty:latest /ty /bin/
|
|||
The following tags are available:
|
||||
|
||||
- `ghcr.io/astral-sh/ty:latest`
|
||||
- `ghcr.io/astral-sh/ty:{major}.{minor}.{patch}`, e.g., `ghcr.io/astral-sh/ty:0.0.2`
|
||||
- `ghcr.io/astral-sh/ty:{major}.{minor}.{patch}`, e.g., `ghcr.io/astral-sh/ty:0.0.5`
|
||||
- `ghcr.io/astral-sh/ty:{major}.{minor}`, e.g., `ghcr.io/astral-sh/ty:0.0` (the latest patch
|
||||
version)
|
||||
|
||||
|
|
|
|||
1
docs/reference/cli.md
generated
1
docs/reference/cli.md
generated
|
|
@ -56,6 +56,7 @@ over all configuration files.</p>
|
|||
</dd><dt id="ty-check--exit-zero"><a href="#ty-check--exit-zero"><code>--exit-zero</code></a></dt><dd><p>Always use exit code 0, even when there are error-level diagnostics</p>
|
||||
</dd><dt id="ty-check--extra-search-path"><a href="#ty-check--extra-search-path"><code>--extra-search-path</code></a> <i>path</i></dt><dd><p>Additional path to use as a module-resolution source (can be passed multiple times).</p>
|
||||
<p>This is an advanced option that should usually only be used for first-party or third-party modules that are not installed into your Python environment in a conventional way. Use <code>--python</code> to point ty to your Python environment if it is in an unusual location.</p>
|
||||
</dd><dt id="ty-check--force-exclude"><a href="#ty-check--force-exclude"><code>--force-exclude</code></a></dt><dd><p>Enforce exclusions, even for paths passed to ty directly on the command-line. Use <code>--no-force-exclude</code> to disable</p>
|
||||
</dd><dt id="ty-check--help"><a href="#ty-check--help"><code>--help</code></a>, <code>-h</code></dt><dd><p>Print help (see a summary with '-h')</p>
|
||||
</dd><dt id="ty-check--ignore"><a href="#ty-check--ignore"><code>--ignore</code></a> <i>rule</i></dt><dd><p>Disables the rule. Can be specified multiple times.</p>
|
||||
</dd><dt id="ty-check--no-progress"><a href="#ty-check--no-progress"><code>--no-progress</code></a></dt><dd><p>Hide all progress outputs.</p>
|
||||
|
|
|
|||
|
|
@ -66,12 +66,16 @@ ______________________________________________________________________
|
|||
|
||||
Determines the scope of the diagnostics reported by the language server.
|
||||
|
||||
Setting this to `off` is useful if you want to use ty exclusively for the language server features
|
||||
like code completion, hover, go to definition, etc.
|
||||
|
||||
- `off`: Diagnostics are disabled.
|
||||
- `openFilesOnly`: Diagnostics are reported only for files that are currently open in the editor.
|
||||
- `workspace`: Diagnostics are reported for all files in the workspace.
|
||||
|
||||
**Default value**: `"openFilesOnly"`
|
||||
|
||||
**Type**: `"workspace" | "openFilesOnly"`
|
||||
**Type**: `"off" | "workspace" | "openFilesOnly"`
|
||||
|
||||
**Example usage**:
|
||||
|
||||
|
|
|
|||
1217
docs/reference/rules.md
generated
1217
docs/reference/rules.md
generated
File diff suppressed because it is too large
Load diff
272
docs/reference/typing-faq.md
Normal file
272
docs/reference/typing-faq.md
Normal file
|
|
@ -0,0 +1,272 @@
|
|||
# Typing FAQ
|
||||
|
||||
This page answers some commonly asked questions about ty and Python's type system.
|
||||
|
||||
## Why does ty report an error on my code?
|
||||
|
||||
Check the [documentation](https://docs.astral.sh/ty/reference/rules/) for the specific error code
|
||||
you are seeing; it may explain the problem.
|
||||
|
||||
## What is the `Unknown` type and when does it appear?
|
||||
|
||||
`Unknown` is ty's way of representing a type that could not be fully inferred. It behaves the same
|
||||
way as `Any`, but appears implicitly, rather than through an explicit `Any` annotation:
|
||||
|
||||
```py
|
||||
from missing_module import MissingClass # error: unresolved-import
|
||||
|
||||
reveal_type(MissingClass) # Unknown
|
||||
```
|
||||
|
||||
ty also uses unions with `Unknown` to maintain the
|
||||
[gradual guarantee](../features/type-system.md#gradual-guarantee), which helps avoid false positive
|
||||
errors in untyped code while still providing useful type information where possible.
|
||||
|
||||
For example, consider the following untyped `Message` class (which could come from a third-party
|
||||
dependency that you have no control over). ty treats the `data` attribute as having type
|
||||
`Unknown | None`, since there is no type annotation that restricts it further. The `Unknown` in the
|
||||
union allows ty to avoid raising errors on the `msg.data = …` assignment. On the other hand, the
|
||||
`None` in the union reflects the fact that `data` *could* possibly be `None`, and requires code that
|
||||
uses `msg.data` to handle that case explicitly.
|
||||
|
||||
```py
|
||||
class Message:
|
||||
data = None
|
||||
|
||||
def __init__(self, title):
|
||||
self.title = title
|
||||
|
||||
|
||||
def receive(msg: Message):
|
||||
reveal_type(msg.data) # Unknown | None
|
||||
|
||||
|
||||
msg = Message("Favorite color")
|
||||
msg.data = {"color": "blue"}
|
||||
```
|
||||
|
||||
([Full example in the playground](https://play.ty.dev/862941a8-a3f6-4818-9ea1-d9d59b0bd2fa))
|
||||
|
||||
## Why does ty show `int | float` when I annotate something as `float`?
|
||||
|
||||
The [Python typing specification](https://typing.python.org/en/latest/spec/special-types.html)
|
||||
includes a special rule for numeric types where an `int` can be used wherever a `float` is expected:
|
||||
|
||||
```py
|
||||
def circle_area(radius: float) -> float:
|
||||
return 3.14 * radius * radius
|
||||
|
||||
circle_area(2) # OK: int is allowed where float is expected
|
||||
```
|
||||
|
||||
This rule is a special case, since `int` is not actually a subclass of `float`. To support this, ty
|
||||
treats `float` annotations as meaning `int | float`. Unlike some other type checkers, ty makes this
|
||||
behavior explicit in type hints and error messages. For example, if you
|
||||
[hover over the `radius` parameter](https://play.ty.dev/fdc144c6-031c-4af9-b520-a4c6ccde9261), ty
|
||||
will show `int | float`.
|
||||
|
||||
A similar rule applies to `complex`, which is treated as `int | float | complex`.
|
||||
|
||||
!!! info
|
||||
|
||||
These special rules for `float` and `complex` exist for a reason. In almost all cases, you
|
||||
probably want to accept both `int` and `float` when you annotate something as `float`.
|
||||
If you really need to accept *only* `float` and not `int`, you can use ty's `JustFloat`
|
||||
type. At the time of writing, this import needs to be guarded by a `TYPE_CHECKING` block:
|
||||
|
||||
```py
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from ty_extensions import JustFloat
|
||||
else:
|
||||
JustFloat = float
|
||||
|
||||
def only_actual_floats_allowed(f: JustFloat) -> None: ...
|
||||
|
||||
only_actual_floats_allowed(1.0) # OK
|
||||
only_actual_floats_allowed(1) # error: invalid-argument-type
|
||||
```
|
||||
|
||||
([Full example in the playground](https://play.ty.dev/fb034780-3ba7-4c6a-9449-5b0f44128bab))
|
||||
|
||||
If you need this for `complex`, you can use `ty_extensions.JustComplex` in a similar way.
|
||||
|
||||
## Why does ty say `Callable` has no attribute `__name__`?
|
||||
|
||||
When you access `__name__`, `__qualname__`, `__module__`, or `__doc__` on a value typed as `Callable`,
|
||||
ty reports an `unresolved-attribute` error. This is because not all callables have these attributes.
|
||||
Functions do (including lambdas), but other callable objects do not. The `FileUpload` class below, for
|
||||
example, is callable, but instances of `FileUpload` do not have a `__name__` attribute. Passing a
|
||||
`FileUpload` instance to `retry` would lead to an `AttributeError` at runtime.
|
||||
|
||||
```py
|
||||
from typing import Callable
|
||||
|
||||
def retry(times: int, operation: Callable[[], bool]) -> bool:
|
||||
for i in range(times):
|
||||
# WRONG: `operation` does not necessarily have a `__name__` attribute
|
||||
print(f"Calling {operation.__name__}, attempt {i + 1} of {times}")
|
||||
if operation():
|
||||
return True
|
||||
return False
|
||||
|
||||
class FileUpload:
|
||||
def __init__(self, name: str) -> None:
|
||||
# …
|
||||
|
||||
def __call__(self) -> bool:
|
||||
# …
|
||||
|
||||
retry(3, FileUpload("image.png"))
|
||||
```
|
||||
|
||||
To fix this, you could use `getattr` with a fall back to a default name when the
|
||||
attribute is not present (or use a `hasattr(…, "__name__")` check if you access
|
||||
it multiple times):
|
||||
|
||||
```py
|
||||
name = getattr(operation, "__name__", "operation")
|
||||
```
|
||||
|
||||
Alternatively, you could use an `isinstance(…, types.FunctionType)` check to narrow the type of
|
||||
`operation` to something that definitely has a `__name__` attribute:
|
||||
|
||||
```py
|
||||
if isinstance(operation, FunctionType):
|
||||
print(f"Calling {operation.__name__}, attempt {i + 1} of {times}")
|
||||
else:
|
||||
print(f"Calling operation, attempt {i + 1} of {times}")
|
||||
```
|
||||
|
||||
You can try various approaches in [this playground example](https://play.ty.dev/f6f7f35a-47c3-423d-be8d-33d03c61d40c).
|
||||
See also [this discussion](https://github.com/astral-sh/ty/issues/1495) for some plans to improve
|
||||
the developer experience around this in the future.
|
||||
|
||||
!!! info
|
||||
|
||||
ty has first-class support for intersection types. If you only want to accept function-like
|
||||
callables, you could define `FunctionLikeCallable` as an intersection of `Callable` and
|
||||
`types.FunctionType`:
|
||||
|
||||
```py
|
||||
from typing import Callable, TYPE_CHECKING
|
||||
from types import FunctionType
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from ty_extensions import Intersection
|
||||
|
||||
type FunctionLikeCallable[**P, R] = Intersection[Callable[P, R], FunctionType]
|
||||
else:
|
||||
FunctionLikeCallable = Callable
|
||||
|
||||
|
||||
def retry(times: int, operation: FunctionLikeCallable[[], bool]) -> bool:
|
||||
...
|
||||
```
|
||||
|
||||
You can check out the full example [here](https://play.ty.dev/7a1ea4ab-04e1-4271-adf5-ddc3a5d2fcfd),
|
||||
which demonstrates that `FileUpload` instances are no longer accepted by `retry`.
|
||||
|
||||
## Does ty have a strict mode?
|
||||
|
||||
Not yet. A stricter inference mode is tracked in
|
||||
[this issue](https://github.com/astral-sh/ty/issues/1240). In the meantime, you can consider using Ruff's
|
||||
[`flake8-annotations` rules](https://docs.astral.sh/ruff/rules/#flake8-annotations-ann) to enforce
|
||||
more explicit type annotations in your code.
|
||||
|
||||
## Why can't ty resolve my imports?
|
||||
|
||||
Import resolution issues are often caused by a missing or incorrect environment configuration. When
|
||||
ty reports *"Cannot resolve imported module …"*, check the following:
|
||||
|
||||
1. **Virtual environment**: Make sure your virtual environment is discoverable. ty looks for an
|
||||
active virtual environment via `VIRTUAL_ENV` or a `.venv` directory in your project root. See the
|
||||
[module discovery](../modules.md#python-environment) documentation for more details.
|
||||
|
||||
1. **Project structure**: If your source code is not in the project root or `src/` directory,
|
||||
configure [`environment.root`](./configuration.md#root) in your `pyproject.toml`:
|
||||
|
||||
```toml
|
||||
[tool.ty.environment]
|
||||
root = ["./app"]
|
||||
```
|
||||
|
||||
1. **Third-party packages**: Ensure dependencies are installed in your virtual environment. Run ty
|
||||
with `-v` to see the search paths being used.
|
||||
|
||||
1. **Compiled extensions**: ty requires `.py` or `.pyi` files for type information. If a package
|
||||
contains only compiled extensions (`.so` or `.pyd` files), you'll need stub files (`.pyi`) for ty
|
||||
to understand the types. See also [this issue](https://github.com/astral-sh/ty/issues/487) which
|
||||
tracks improvements in this area.
|
||||
|
||||
## Does ty support monorepos?
|
||||
|
||||
ty can work with monorepos, but automatic discovery of nested projects is limited. By default, ty
|
||||
uses the current working directory or the `--project` option to determine the project root.
|
||||
|
||||
For monorepos with multiple Python packages, you have a few options:
|
||||
|
||||
1. **Run ty per-package**: Run `ty check` from each package directory, or use `--project` to specify
|
||||
the package:
|
||||
|
||||
```bash
|
||||
ty check --project packages/package-a
|
||||
ty check --project packages/package-b
|
||||
```
|
||||
|
||||
1. **Configure multiple source roots**: Use [`environment.root`](./configuration.md#root) to specify
|
||||
multiple source directories:
|
||||
|
||||
```toml
|
||||
[tool.ty.environment]
|
||||
root = ["packages/package-a", "packages/package-b"]
|
||||
```
|
||||
|
||||
This has the disadvantage of treating all packages as a single project, which may lead to cases
|
||||
in which ty thinks something is importable when it wouldn't be at runtime.
|
||||
|
||||
You can follow [this issue](https://github.com/astral-sh/ty/issues/819) to get updates on this
|
||||
topic.
|
||||
|
||||
## Does ty support PEP 723 inline-metadata scripts?
|
||||
|
||||
It depends on what you want to do. If you have a single inline-metadata script, you can type check
|
||||
it with ty by using uv's `--with-requirements` flag to install the dependencies specified in the
|
||||
script header:
|
||||
|
||||
```bash
|
||||
uvx --with-requirements script.py ty check script.py
|
||||
```
|
||||
|
||||
If you have multiple scripts in your workspace, ty does not yet recognize that they have different
|
||||
dependencies based on their inline metadata.
|
||||
|
||||
You can follow [this issue](https://github.com/astral-sh/ty/issues/691) for updates.
|
||||
|
||||
## Is there a pre-commit hook for ty?
|
||||
|
||||
Not yet. You can track progress in [this issue](https://github.com/astral-sh/ty/issues/269), which
|
||||
also includes some suggested manual hooks you can use in the meantime.
|
||||
|
||||
## Does ty support (mypy) plugins?
|
||||
|
||||
No. ty does not have a plugin system and there is currently no plan to add one.
|
||||
|
||||
We prefer extending the type system with well-specified features rather than relying on
|
||||
type-checker-specific plugins. That said, we are considering adding support for popular third-party
|
||||
libraries like pydantic, SQLAlchemy, attrs, or django directly into ty.
|
||||
|
||||
## What is `Top[list[Unknown]]`, and why does it appear?
|
||||
|
||||
This type represents "all possible lists of any element type" (as opposed to `list[Unknown]`, which
|
||||
represents "a list of some unknown element type"). It usually arises from a check such as
|
||||
`if isinstance(x, list):`. If `x` was previously of type `Item | list[Item]`, you might expect this
|
||||
check to narrow the type to `list[Item]`, but ty respects the possibility that there could be a
|
||||
common subclass of both `Item` and `list` (which may not be a list of `Item`!), and so the narrowed
|
||||
type is instead `(Item & Top[list[Unknown]]) | list[Item]`. This code can be made more robust by
|
||||
instead checking `if instance(x, Item)`, or by declaring the `Item` type as `@typing.final`.
|
||||
|
||||
See also the [discussion
|
||||
here](https://docs.astral.sh/ty/features/type-system/#top-and-bottom-materializations) and [in this
|
||||
issue](https://github.com/astral-sh/ty/issues/1578).
|
||||
|
|
@ -99,6 +99,7 @@ nav:
|
|||
- Language server: features/language-server.md
|
||||
- Reference:
|
||||
- Configuration: reference/configuration.md
|
||||
- Typing FAQ: reference/typing-faq.md
|
||||
- Rules: reference/rules.md
|
||||
- CLI: reference/cli.md
|
||||
- Exit codes: reference/exit-codes.md
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
[project]
|
||||
name = "ty"
|
||||
version = "0.0.2"
|
||||
version = "0.0.5"
|
||||
requires-python = ">=3.8"
|
||||
dependencies = []
|
||||
description = "An extremely fast Python type checker, written in Rust."
|
||||
|
|
@ -102,6 +102,7 @@ include = [
|
|||
version-files = [
|
||||
"pyproject.toml",
|
||||
{ path = "dist-workspace.toml", field = "workspace.version", format = "cargo" },
|
||||
"docs/installation.md",
|
||||
]
|
||||
submodules = ["ruff"]
|
||||
require-labels = [{ submodule = "ruff", labels = ["ty"] }]
|
||||
|
|
@ -117,7 +118,6 @@ changelog-ignore-authors = ["github-actions"]
|
|||
major-labels = [] # We do not use the major version number yet
|
||||
minor-labels = [] # We do not use the minor version number yet
|
||||
version-format = "cargo"
|
||||
default-bump-type = "pre"
|
||||
trim-title-prefixes = ["[ty]"]
|
||||
|
||||
[tool.rooster.section-labels]
|
||||
|
|
|
|||
2
ruff
2
ruff
|
|
@ -1 +1 @@
|
|||
Subproject commit ad3de4e4881a15545fc85fdfaf5374df7793538d
|
||||
Subproject commit ad41728204681a60e6d9761857b000cb6bfe732b
|
||||
2
uv.lock
generated
2
uv.lock
generated
|
|
@ -624,7 +624,7 @@ wheels = [
|
|||
|
||||
[[package]]
|
||||
name = "ty"
|
||||
version = "0.0.2"
|
||||
version = "0.0.5"
|
||||
source = { editable = "." }
|
||||
|
||||
[package.dev-dependencies]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue