mirror of
https://github.com/astral-sh/ty.git
synced 2025-08-04 17:08:04 +00:00
Bump version to 0.0.1a1 (#356)
Co-authored-by: Dhruv Manilawala <dhruvmanila@gmail.com> Co-authored-by: David Peter <mail@david-peter.de>
This commit is contained in:
parent
fa321ae83a
commit
12f466e461
8 changed files with 370 additions and 97 deletions
48
CHANGELOG.md
48
CHANGELOG.md
|
@ -1,5 +1,53 @@
|
|||
# Changelog
|
||||
|
||||
## 0.0.1a1
|
||||
|
||||
### Enhancements
|
||||
|
||||
- Add basic support for non-virtual Python environments ([#17991](https://github.com/astral-sh/ruff/pull/17991))
|
||||
- Do not allow invalid virtual environments from discovered `.venv` or `VIRTUAL_ENV` ([#18003](https://github.com/astral-sh/ruff/pull/18003))
|
||||
- Refine message for why a rule is enabled ([#18038](https://github.com/astral-sh/ruff/pull/18038))
|
||||
- Update `--python` to accept paths to executables in environments ([#17954](https://github.com/astral-sh/ruff/pull/17954))
|
||||
- Improve diagnostics for `assert_type` and `assert_never` ([#18050](https://github.com/astral-sh/ruff/pull/18050))
|
||||
- Add a note to the diagnostic if a new builtin is used on an old Python version ([#18068](https://github.com/astral-sh/ruff/pull/18068))
|
||||
|
||||
### Bug fixes
|
||||
|
||||
- Fix infinite recursion bug in `is_disjoint_from` ([#18043](https://github.com/astral-sh/ruff/pull/18043))
|
||||
- Recognize submodules in self-referential imports ([#18005](https://github.com/astral-sh/ruff/pull/18005))
|
||||
|
||||
### Typing
|
||||
|
||||
- Allow a class to inherit from an intersection if the intersection contains a dynamic type and the intersection is not disjoint from `type` ([#18055](https://github.com/astral-sh/ruff/pull/18055))
|
||||
- Allow classes to inherit from `type[Any]` or `type[Unknown]` ([#18060](https://github.com/astral-sh/ruff/pull/18060))
|
||||
- Apply function specialization to all overloads ([#18020](https://github.com/astral-sh/ruff/pull/18020))
|
||||
- Implement `DataClassInstance` protocol for dataclasses ([#18018](https://github.com/astral-sh/ruff/pull/18018))
|
||||
- Induct into instances and subclasses when finding and applying generics ([#18052](https://github.com/astral-sh/ruff/pull/18052))
|
||||
- Infer parameter specializations of generic aliases ([#18021](https://github.com/astral-sh/ruff/pull/18021))
|
||||
- Narrowing for `hasattr()` ([#18053](https://github.com/astral-sh/ruff/pull/18053))
|
||||
- Silence false positives for PEP-695 ParamSpec annotations ([#18001](https://github.com/astral-sh/ruff/pull/18001))
|
||||
- Understand homogeneous tuple annotations ([#17998](https://github.com/astral-sh/ruff/pull/17998))
|
||||
- `__file__` is always a string inside a Python module ([#18071](https://github.com/astral-sh/ruff/pull/18071))
|
||||
|
||||
### CLI
|
||||
|
||||
- Avoid initializing progress bars early ([#18049](https://github.com/astral-sh/ruff/pull/18049))
|
||||
|
||||
### Contributors
|
||||
|
||||
- [@soof-golan](https://github.com/soof-golan)
|
||||
- [@ibraheemdev](https://github.com/ibraheemdev)
|
||||
- [@dhruvmanila](https://github.com/dhruvmanila)
|
||||
- [@charliermarsh](https://github.com/charliermarsh)
|
||||
- [@MichaReiser](https://github.com/MichaReiser)
|
||||
- [@carljm](https://github.com/carljm)
|
||||
- [@abhijeetbodas2001](https://github.com/abhijeetbodas2001)
|
||||
- [@zanieb](https://github.com/zanieb)
|
||||
- [@AlexWaygood](https://github.com/AlexWaygood)
|
||||
- [@dcreager](https://github.com/dcreager)
|
||||
- [@mtshiba](https://github.com/mtshiba)
|
||||
- [@sharkdp](https://github.com/sharkdp)
|
||||
|
||||
## 0.0.0a8
|
||||
|
||||
### Changes
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
[workspace]
|
||||
members = ["cargo:./ruff"]
|
||||
packages = ["ty"]
|
||||
version = "0.0.0-alpha.8"
|
||||
version = "0.0.1-alpha.1"
|
||||
|
||||
# Config for 'dist'
|
||||
[dist]
|
||||
|
|
|
@ -56,13 +56,17 @@ ty check [OPTIONS] [PATH]...
|
|||
</ul></dd><dt id="ty-check--project"><a href="#ty-check--project"><code>--project</code></a> <i>project</i></dt><dd><p>Run the command within the given project directory.</p>
|
||||
<p>All <code>pyproject.toml</code> files will be discovered by walking up the directory tree from the given project directory, as will the project's virtual environment (<code>.venv</code>) unless the <code>venv-path</code> option is set.</p>
|
||||
<p>Other command-line arguments (such as relative paths) will be resolved relative to the current working directory.</p>
|
||||
</dd><dt id="ty-check--python"><a href="#ty-check--python"><code>--python</code></a> <i>path</i></dt><dd><p>Path to the Python installation from which ty resolves type information and third-party dependencies.</p>
|
||||
<p>If not specified, ty will look at the <code>VIRTUAL_ENV</code> environment variable.</p>
|
||||
<p>ty will search in the path's <code>site-packages</code> directories for type information and third-party imports.</p>
|
||||
<p>This option is commonly used to specify the path to a virtual environment.</p>
|
||||
</dd><dt id="ty-check--python"><a href="#ty-check--python"><code>--python</code></a> <i>path</i></dt><dd><p>Path to the Python environment.</p>
|
||||
<p>ty uses the Python environment to resolve type information and third-party dependencies.</p>
|
||||
<p>If not specified, ty will attempt to infer it from the <code>VIRTUAL_ENV</code> environment variable or discover a <code>.venv</code> directory in the project root or working directory.</p>
|
||||
<p>If a path to a Python interpreter is provided, e.g., <code>.venv/bin/python3</code>, ty will attempt to find an environment two directories up from the interpreter's path, e.g., <code>.venv</code>. At this time, ty does not invoke the interpreter to determine the location of the environment. This means that ty will not resolve dynamic executables such as a shim.</p>
|
||||
<p>ty will search in the resolved environments's <code>site-packages</code> directories for type information and third-party imports.</p>
|
||||
</dd><dt id="ty-check--python-platform"><a href="#ty-check--python-platform"><code>--python-platform</code></a>, <code>--platform</code> <i>platform</i></dt><dd><p>Target platform to assume when resolving types.</p>
|
||||
<p>This is used to specialize the type of <code>sys.platform</code> and will affect the visibility of platform-specific functions and attributes. If the value is set to <code>all</code>, no assumptions are made about the target platform. If unspecified, the current system's platform will be used.</p>
|
||||
</dd><dt id="ty-check--python-version"><a href="#ty-check--python-version"><code>--python-version</code></a>, <code>--target-version</code> <i>version</i></dt><dd><p>Python version to assume when resolving types</p>
|
||||
</dd><dt id="ty-check--python-version"><a href="#ty-check--python-version"><code>--python-version</code></a>, <code>--target-version</code> <i>version</i></dt><dd><p>Python version to assume when resolving types.</p>
|
||||
<p>The Python version affects allowed syntax, type definitions of the standard library, and type definitions of first- and third-party modules that are conditional on the Python version.</p>
|
||||
<p>By default, the Python version is inferred as the lower bound of the project's <code>requires-python</code> field from the <code>pyproject.toml</code>, if available. Otherwise, the latest stable version supported by ty is used, which is currently 3.13.</p>
|
||||
<p>ty will not infer the Python version from the Python environment at this time.</p>
|
||||
<p>Possible values:</p>
|
||||
<ul>
|
||||
<li><code>3.7</code></li>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# Configuration
|
||||
#### [`respect-ignore-files`]
|
||||
#### `respect-ignore-files`
|
||||
|
||||
Whether to automatically exclude files that are ignored by `.ignore`,
|
||||
`.gitignore`, `.git/info/exclude`, and global `gitignore` files.
|
||||
|
@ -18,11 +18,11 @@ respect-ignore-files = false
|
|||
|
||||
---
|
||||
|
||||
#### [`rules`]
|
||||
#### `rules`
|
||||
|
||||
Configures the enabled rules and their severity.
|
||||
|
||||
See [the rules documentation](https://github.com/astral-sh/ruff/blob/main/crates/ty/docs/rules.md) for a list of all available rules.
|
||||
See [the rules documentation](https://github.com/astral-sh/ty/blob/main/docs/rules.md) for a list of all available rules.
|
||||
|
||||
Valid severities are:
|
||||
|
||||
|
@ -47,7 +47,7 @@ division-by-zero = "ignore"
|
|||
|
||||
## `environment`
|
||||
|
||||
#### [`extra-paths`]
|
||||
#### `extra-paths`
|
||||
|
||||
List of user-provided paths that should take first priority in the module resolution.
|
||||
Examples in other type checkers are mypy's `MYPYPATH` environment variable,
|
||||
|
@ -66,7 +66,7 @@ extra-paths = ["~/shared/my-search-path"]
|
|||
|
||||
---
|
||||
|
||||
#### [`python`]
|
||||
#### `python`
|
||||
|
||||
Path to the Python installation from which ty resolves type information and third-party dependencies.
|
||||
|
||||
|
@ -88,7 +88,7 @@ python = "./.venv"
|
|||
|
||||
---
|
||||
|
||||
#### [`python-platform`]
|
||||
#### `python-platform`
|
||||
|
||||
Specifies the target platform that will be used to analyze the source code.
|
||||
If specified, ty will understand conditions based on comparisons with `sys.platform`, such
|
||||
|
@ -115,7 +115,7 @@ python-platform = "win32"
|
|||
|
||||
---
|
||||
|
||||
#### [`python-version`]
|
||||
#### `python-version`
|
||||
|
||||
Specifies the version of Python that will be used to analyze the source code.
|
||||
The version should be specified as a string in the format `M.m` where `M` is the major version
|
||||
|
@ -139,7 +139,7 @@ python-version = "3.12"
|
|||
|
||||
---
|
||||
|
||||
#### [`typeshed`]
|
||||
#### `typeshed`
|
||||
|
||||
Optional path to a "typeshed" directory on disk for us to use for standard-library types.
|
||||
If this is not provided, we will fallback to our vendored typeshed stubs for the stdlib,
|
||||
|
@ -160,26 +160,26 @@ typeshed = "/path/to/custom/typeshed"
|
|||
|
||||
## `src`
|
||||
|
||||
#### [`root`]
|
||||
#### `root`
|
||||
|
||||
The root(s) of the project, used for finding first-party modules.
|
||||
The root of the project, used for finding first-party modules.
|
||||
|
||||
**Default value**: `[".", "./src"]`
|
||||
|
||||
**Type**: `list[str]`
|
||||
**Type**: `str`
|
||||
|
||||
**Example usage** (`pyproject.toml`):
|
||||
|
||||
```toml
|
||||
[tool.ty.src]
|
||||
root = ["./app"]
|
||||
root = "./app"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## `terminal`
|
||||
|
||||
#### [`error-on-warning`]
|
||||
#### `error-on-warning`
|
||||
|
||||
Use exit code 1 if there are any warning-level diagnostics.
|
||||
|
||||
|
@ -199,7 +199,7 @@ error-on-warning = true
|
|||
|
||||
---
|
||||
|
||||
#### [`output-format`]
|
||||
#### `output-format`
|
||||
|
||||
The format to use for printing diagnostic messages.
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ Calling a non-callable object will raise a `TypeError` at runtime.
|
|||
|
||||
### Links
|
||||
* [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20call-non-callable)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L84)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L85)
|
||||
</details>
|
||||
|
||||
## `conflicting-argument-forms`
|
||||
|
@ -61,11 +61,27 @@ Calling a non-callable object will raise a `TypeError` at runtime.
|
|||
<summary>detects when an argument is used as both a value and a type form in a call</summary>
|
||||
|
||||
### What it does
|
||||
Checks whether an argument is used as both a value and a type form in a call
|
||||
Checks whether an argument is used as both a value and a type form in a call.
|
||||
|
||||
### Why is this bad?
|
||||
Such calls have confusing semantics and often indicate a logic error.
|
||||
|
||||
### Examples
|
||||
```python
|
||||
from typing import reveal_type
|
||||
from ty_extensions import is_fully_static
|
||||
|
||||
if flag:
|
||||
f = repr # Expects a value
|
||||
else:
|
||||
f = is_fully_static # Expects a type form
|
||||
|
||||
f(int) # error
|
||||
```
|
||||
|
||||
### Links
|
||||
* [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20conflicting-argument-forms)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L115)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L116)
|
||||
</details>
|
||||
|
||||
## `conflicting-declarations`
|
||||
|
@ -83,9 +99,19 @@ A variable with two conflicting declarations likely indicates a mistake.
|
|||
Moreover, it could lead to incorrect or ill-defined type inference for
|
||||
other code that relies on these variables.
|
||||
|
||||
### Examples
|
||||
```python
|
||||
if b:
|
||||
a: int
|
||||
else:
|
||||
a: str
|
||||
|
||||
a = 1
|
||||
```
|
||||
|
||||
### Links
|
||||
* [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20conflicting-declarations)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L125)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L142)
|
||||
</details>
|
||||
|
||||
## `conflicting-metaclass`
|
||||
|
@ -95,11 +121,28 @@ other code that relies on these variables.
|
|||
<details>
|
||||
<summary>detects conflicting metaclasses</summary>
|
||||
|
||||
TODO #14889
|
||||
### What it does
|
||||
Checks for class definitions where the metaclass of the class
|
||||
being created would not be a subclass of the metaclasses of
|
||||
all the class's bases.
|
||||
|
||||
### Why is it bad?
|
||||
Such a class definition raises a `TypeError` at runtime.
|
||||
|
||||
### Examples
|
||||
```python
|
||||
class M1(type): ...
|
||||
class M2(type): ...
|
||||
class A(metaclass=M1): ...
|
||||
class B(metaclass=M2): ...
|
||||
|
||||
## TypeError: metaclass conflict
|
||||
class C(A, B): ...
|
||||
```
|
||||
|
||||
### Links
|
||||
* [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20conflicting-metaclass)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L140)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L167)
|
||||
</details>
|
||||
|
||||
## `cyclic-class-definition`
|
||||
|
@ -110,14 +153,27 @@ TODO #14889
|
|||
<summary>detects cyclic class definitions</summary>
|
||||
|
||||
### What it does
|
||||
Checks for class definitions with a cyclic inheritance chain.
|
||||
Checks for class definitions in stub files that inherit
|
||||
(directly or indirectly) from themselves.
|
||||
|
||||
### Why is it bad?
|
||||
TODO #14889
|
||||
Although forward references are natively supported in stub files,
|
||||
inheritance cycles are still disallowed, as it is impossible to
|
||||
resolve a consistent [method resolution order] for a class that
|
||||
inherits from itself.
|
||||
|
||||
### Examples
|
||||
```python
|
||||
## foo.pyi
|
||||
class A(B): ...
|
||||
class B(A): ...
|
||||
```
|
||||
|
||||
[method resolution order]: https://docs.python.org/3/glossary.html#term-method-resolution-order
|
||||
|
||||
### Links
|
||||
* [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20cyclic-class-definition)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L149)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L193)
|
||||
</details>
|
||||
|
||||
## `division-by-zero`
|
||||
|
@ -140,7 +196,7 @@ Dividing by zero raises a `ZeroDivisionError` at runtime.
|
|||
|
||||
### Links
|
||||
* [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20division-by-zero)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L162)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L219)
|
||||
</details>
|
||||
|
||||
## `duplicate-base`
|
||||
|
@ -154,11 +210,19 @@ Dividing by zero raises a `ZeroDivisionError` at runtime.
|
|||
Checks for class definitions with duplicate bases.
|
||||
|
||||
### Why is this bad?
|
||||
Class definitions with duplicate bases raise a `TypeError` at runtime.
|
||||
Class definitions with duplicate bases raise `TypeError` at runtime.
|
||||
|
||||
### Examples
|
||||
```python
|
||||
class A: ...
|
||||
|
||||
## TypeError: duplicate base class
|
||||
class B(A, A): ...
|
||||
```
|
||||
|
||||
### Links
|
||||
* [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20duplicate-base)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L180)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L237)
|
||||
</details>
|
||||
|
||||
## `escape-character-in-forward-annotation`
|
||||
|
@ -295,7 +359,7 @@ TypeError: multiple bases have instance lay-out conflict
|
|||
|
||||
### Links
|
||||
* [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20incompatible-slots)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L193)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L258)
|
||||
</details>
|
||||
|
||||
## `inconsistent-mro`
|
||||
|
@ -306,14 +370,25 @@ TypeError: multiple bases have instance lay-out conflict
|
|||
<summary>detects class definitions with an inconsistent MRO</summary>
|
||||
|
||||
### What it does
|
||||
Checks for classes with an inconsistent method resolution order (MRO).
|
||||
Checks for classes with an inconsistent [method resolution order] (MRO).
|
||||
|
||||
### Why is this bad?
|
||||
Classes with an inconsistent MRO will raise a `TypeError` at runtime.
|
||||
|
||||
### Examples
|
||||
```python
|
||||
class A: ...
|
||||
class B(A): ...
|
||||
|
||||
## TypeError: Cannot create a consistent method resolution order
|
||||
class C(A, B): ...
|
||||
```
|
||||
|
||||
[method resolution order]: https://docs.python.org/3/glossary.html#term-method-resolution-order
|
||||
|
||||
### Links
|
||||
* [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20inconsistent-mro)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L279)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L344)
|
||||
</details>
|
||||
|
||||
## `index-out-of-bounds`
|
||||
|
@ -330,9 +405,15 @@ a container.
|
|||
### Why is this bad?
|
||||
Using an out of bounds index will raise an `IndexError` at runtime.
|
||||
|
||||
### Examples
|
||||
```python
|
||||
t = (0, 1, 2)
|
||||
t[3] # IndexError: tuple index out of range
|
||||
```
|
||||
|
||||
### Links
|
||||
* [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20index-out-of-bounds)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L292)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L368)
|
||||
</details>
|
||||
|
||||
## `invalid-argument-type`
|
||||
|
@ -358,7 +439,7 @@ func("foo") # error: [invalid-argument-type]
|
|||
|
||||
### Links
|
||||
* [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-argument-type)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L306)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L388)
|
||||
</details>
|
||||
|
||||
## `invalid-assignment`
|
||||
|
@ -368,11 +449,24 @@ func("foo") # error: [invalid-argument-type]
|
|||
<details>
|
||||
<summary>detects invalid assignments</summary>
|
||||
|
||||
TODO #14889
|
||||
### What it does
|
||||
Checks for assignments where the type of the value
|
||||
is not [assignable to] the type of the assignee.
|
||||
|
||||
### Why is this bad?
|
||||
Such assignments break the rules of the type system and
|
||||
weaken a type checker's ability to accurately reason about your code.
|
||||
|
||||
### Examples
|
||||
```python
|
||||
a: int = ''
|
||||
```
|
||||
|
||||
[assignable to]: https://typing.python.org/en/latest/spec/glossary.html#term-assignable
|
||||
|
||||
### Links
|
||||
* [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-assignment)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L346)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L428)
|
||||
</details>
|
||||
|
||||
## `invalid-attribute-access`
|
||||
|
@ -383,20 +477,29 @@ TODO #14889
|
|||
<summary>Invalid attribute access</summary>
|
||||
|
||||
### What it does
|
||||
Makes sure that instance attribute accesses are valid.
|
||||
Checks for assignments to class variables from instances
|
||||
and assignments to instance variables from its class.
|
||||
|
||||
### Why is this bad?
|
||||
Incorrect assignments break the rules of the type system and
|
||||
weaken a type checker's ability to accurately reason about your code.
|
||||
|
||||
### Examples
|
||||
```python
|
||||
class C:
|
||||
var: ClassVar[int] = 1
|
||||
class_var: ClassVar[int] = 1
|
||||
instance_var: int
|
||||
|
||||
C.var = 3 # okay
|
||||
C().var = 3 # error: Cannot assign to class variable
|
||||
C.class_var = 3 # okay
|
||||
C().class_var = 3 # error: Cannot assign to class variable
|
||||
|
||||
C().instance_var = 3 # okay
|
||||
C.instance_var = 3 # error: Cannot assign to instance variable
|
||||
```
|
||||
|
||||
### Links
|
||||
* [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-attribute-access)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1099)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1312)
|
||||
</details>
|
||||
|
||||
## `invalid-base`
|
||||
|
@ -404,13 +507,13 @@ C().var = 3 # error: Cannot assign to class variable
|
|||
**Default level**: error
|
||||
|
||||
<details>
|
||||
<summary>detects class definitions with an invalid base</summary>
|
||||
<summary>detects invalid bases in class definitions</summary>
|
||||
|
||||
TODO #14889
|
||||
|
||||
### Links
|
||||
* [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-base)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L355)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L450)
|
||||
</details>
|
||||
|
||||
## `invalid-context-manager`
|
||||
|
@ -420,11 +523,23 @@ TODO #14889
|
|||
<details>
|
||||
<summary>detects expressions used in with statements that don't implement the context manager protocol</summary>
|
||||
|
||||
TODO #14889
|
||||
### What it does
|
||||
Checks for expressions used in `with` statements
|
||||
that do not implement the context manager protocol.
|
||||
|
||||
### Why is this bad?
|
||||
Such a statement will raise `TypeError` at runtime.
|
||||
|
||||
### Examples
|
||||
```python
|
||||
## TypeError: 'int' object does not support the context manager protocol
|
||||
with 1:
|
||||
print(2)
|
||||
```
|
||||
|
||||
### Links
|
||||
* [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-context-manager)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L364)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L459)
|
||||
</details>
|
||||
|
||||
## `invalid-declaration`
|
||||
|
@ -434,11 +549,25 @@ TODO #14889
|
|||
<details>
|
||||
<summary>detects invalid declarations</summary>
|
||||
|
||||
TODO #14889
|
||||
### What it does
|
||||
Checks for declarations where the inferred type of an existing symbol
|
||||
is not [assignable to] its post-hoc declared type.
|
||||
|
||||
### Why is this bad?
|
||||
Such declarations break the rules of the type system and
|
||||
weaken a type checker's ability to accurately reason about your code.
|
||||
|
||||
### Examples
|
||||
```python
|
||||
a = 1
|
||||
a: str
|
||||
```
|
||||
|
||||
[assignable to]: https://typing.python.org/en/latest/spec/glossary.html#term-assignable
|
||||
|
||||
### Links
|
||||
* [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-declaration)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L373)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L480)
|
||||
</details>
|
||||
|
||||
## `invalid-exception-caught`
|
||||
|
@ -479,7 +608,7 @@ except ZeroDivisionError:
|
|||
|
||||
### Links
|
||||
* [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-exception-caught)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L382)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L503)
|
||||
</details>
|
||||
|
||||
## `invalid-generic-class`
|
||||
|
@ -510,7 +639,7 @@ class C[U](Generic[T]): ...
|
|||
|
||||
### Links
|
||||
* [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-generic-class)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L418)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L539)
|
||||
</details>
|
||||
|
||||
## `invalid-legacy-type-variable`
|
||||
|
@ -543,7 +672,7 @@ def f(t: TypeVar("U")): ...
|
|||
|
||||
### Links
|
||||
* [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-legacy-type-variable)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L444)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L565)
|
||||
</details>
|
||||
|
||||
## `invalid-metaclass`
|
||||
|
@ -575,7 +704,7 @@ class B(metaclass=f): ...
|
|||
|
||||
### Links
|
||||
* [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-metaclass)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L472)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L593)
|
||||
</details>
|
||||
|
||||
## `invalid-overload`
|
||||
|
@ -623,7 +752,7 @@ def foo(x: int) -> int: ...
|
|||
|
||||
### Links
|
||||
* [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-overload)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L499)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L620)
|
||||
</details>
|
||||
|
||||
## `invalid-parameter-default`
|
||||
|
@ -634,14 +763,21 @@ def foo(x: int) -> int: ...
|
|||
<summary>detects default values that can't be assigned to the parameter's annotated type</summary>
|
||||
|
||||
### What it does
|
||||
Checks for default values that can't be assigned to the parameter's annotated type.
|
||||
Checks for default values that can't be
|
||||
assigned to the parameter's annotated type.
|
||||
|
||||
### Why is this bad?
|
||||
TODO #14889
|
||||
This breaks the rules of the type system and
|
||||
weakens a type checker's ability to accurately reason about your code.
|
||||
|
||||
### Examples
|
||||
```python
|
||||
def f(a: int = ''): ...
|
||||
```
|
||||
|
||||
### Links
|
||||
* [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-parameter-default)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L542)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L663)
|
||||
</details>
|
||||
|
||||
## `invalid-protocol`
|
||||
|
@ -674,7 +810,7 @@ TypeError: Protocols can only inherit from other protocols, got <class 'int'>
|
|||
|
||||
### Links
|
||||
* [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-protocol)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L251)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L316)
|
||||
</details>
|
||||
|
||||
## `invalid-raise`
|
||||
|
@ -722,7 +858,7 @@ def g():
|
|||
|
||||
### Links
|
||||
* [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-raise)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L555)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L683)
|
||||
</details>
|
||||
|
||||
## `invalid-return-type`
|
||||
|
@ -746,7 +882,7 @@ def func() -> int:
|
|||
|
||||
### Links
|
||||
* [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-return-type)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L327)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L409)
|
||||
</details>
|
||||
|
||||
## `invalid-super-argument`
|
||||
|
@ -790,7 +926,7 @@ super(B, A) # error: `A` does not satisfy `issubclass(A, B)`
|
|||
|
||||
### Links
|
||||
* [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-super-argument)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L598)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L726)
|
||||
</details>
|
||||
|
||||
## `invalid-syntax-in-forward-annotation`
|
||||
|
@ -825,9 +961,15 @@ code seen only by the type checker, and not at runtime. Normally this flag is im
|
|||
must be assigned the value `False` at runtime; the type checker will consider its value to
|
||||
be `True`. If annotated, it must be annotated as a type that can accept `bool` values.
|
||||
|
||||
### Examples
|
||||
```python
|
||||
TYPE_CHECKING: str
|
||||
TYPE_CHECKING = ''
|
||||
```
|
||||
|
||||
### Links
|
||||
* [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-type-checking-constant)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L637)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L765)
|
||||
</details>
|
||||
|
||||
## `invalid-type-form`
|
||||
|
@ -838,14 +980,24 @@ be `True`. If annotated, it must be annotated as a type that can accept `bool` v
|
|||
<summary>detects invalid type forms</summary>
|
||||
|
||||
### What it does
|
||||
Checks for invalid type expressions.
|
||||
Checks for expressions that are used as type expressions
|
||||
but cannot validly be interpreted as such.
|
||||
|
||||
### Why is this bad?
|
||||
TODO #14889
|
||||
Such expressions cannot be understood by ty.
|
||||
In some cases, they might raise errors at runtime.
|
||||
|
||||
### Examples
|
||||
```python
|
||||
from typing import Annotated
|
||||
|
||||
a: type[1] # `1` is not a type
|
||||
b: Annotated[int] # `Annotated` expects at least two arguments
|
||||
```
|
||||
|
||||
### Links
|
||||
* [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-type-form)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L655)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L789)
|
||||
</details>
|
||||
|
||||
## `invalid-type-variable-constraints`
|
||||
|
@ -855,11 +1007,31 @@ TODO #14889
|
|||
<details>
|
||||
<summary>detects invalid type variable constraints</summary>
|
||||
|
||||
TODO #14889
|
||||
### What it does
|
||||
Checks for constrained [type variables] with only one constraint.
|
||||
|
||||
### Why is this bad?
|
||||
A constrained type variable must have at least two constraints.
|
||||
|
||||
### Examples
|
||||
```python
|
||||
from typing import TypeVar
|
||||
|
||||
T = TypeVar('T', str) # invalid constrained TypeVar
|
||||
```
|
||||
|
||||
Use instead:
|
||||
```python
|
||||
T = TypeVar('T', str, int) # valid constrained TypeVar
|
||||
## or
|
||||
T = TypeVar('T', bound=str) # valid bound TypeVar
|
||||
```
|
||||
|
||||
[type variables]: https://docs.python.org/3/library/typing.html#typing.TypeVar
|
||||
|
||||
### Links
|
||||
* [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-type-variable-constraints)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L668)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L812)
|
||||
</details>
|
||||
|
||||
## `missing-argument`
|
||||
|
@ -883,7 +1055,7 @@ func() # TypeError: func() missing 1 required positional argument: 'x'
|
|||
|
||||
### Links
|
||||
* [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20missing-argument)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L677)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L841)
|
||||
</details>
|
||||
|
||||
## `no-matching-overload`
|
||||
|
@ -911,7 +1083,7 @@ func("string") # error: [no-matching-overload]
|
|||
|
||||
### Links
|
||||
* [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20no-matching-overload)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L696)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L860)
|
||||
</details>
|
||||
|
||||
## `non-subscriptable`
|
||||
|
@ -934,7 +1106,7 @@ Subscripting an object that does not support it will raise a `TypeError` at runt
|
|||
|
||||
### Links
|
||||
* [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20non-subscriptable)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L719)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L883)
|
||||
</details>
|
||||
|
||||
## `not-iterable`
|
||||
|
@ -959,7 +1131,7 @@ for i in 34: # TypeError: 'int' object is not iterable
|
|||
|
||||
### Links
|
||||
* [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20not-iterable)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L737)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L901)
|
||||
</details>
|
||||
|
||||
## `parameter-already-assigned`
|
||||
|
@ -985,7 +1157,7 @@ f(1, x=2) # Error raised here
|
|||
|
||||
### Links
|
||||
* [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20parameter-already-assigned)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L788)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L952)
|
||||
</details>
|
||||
|
||||
## `raw-string-type-annotation`
|
||||
|
@ -1028,6 +1200,11 @@ def test(): -> "int":
|
|||
### What it does
|
||||
Makes sure that the argument of `static_assert` is statically known to be true.
|
||||
|
||||
### Why is this bad?
|
||||
A `static_assert` call represents an explicit request from the user
|
||||
for the type checker to emit an error if the argument cannot be verified
|
||||
to evaluate to `True` in a boolean context.
|
||||
|
||||
### Examples
|
||||
```python
|
||||
from ty_extensions import static_assert
|
||||
|
@ -1039,7 +1216,7 @@ static_assert(int(2.0 * 3.0) == 6) # error: does not have a statically known tr
|
|||
|
||||
### Links
|
||||
* [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20static-assert-error)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1080)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1288)
|
||||
</details>
|
||||
|
||||
## `subclass-of-final-class`
|
||||
|
@ -1067,7 +1244,7 @@ class B(A): ... # Error raised here
|
|||
|
||||
### Links
|
||||
* [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20subclass-of-final-class)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L858)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1043)
|
||||
</details>
|
||||
|
||||
## `too-many-positional-arguments`
|
||||
|
@ -1093,7 +1270,7 @@ f("foo") # Error raised here
|
|||
|
||||
### Links
|
||||
* [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20too-many-positional-arguments)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L903)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1088)
|
||||
</details>
|
||||
|
||||
## `type-assertion-failure`
|
||||
|
@ -1120,7 +1297,7 @@ def _(x: int):
|
|||
|
||||
### Links
|
||||
* [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20type-assertion-failure)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L881)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1066)
|
||||
</details>
|
||||
|
||||
## `unavailable-implicit-super-arguments`
|
||||
|
@ -1164,7 +1341,7 @@ class A:
|
|||
|
||||
### Links
|
||||
* [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20unavailable-implicit-super-arguments)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L924)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1109)
|
||||
</details>
|
||||
|
||||
## `unknown-argument`
|
||||
|
@ -1190,7 +1367,7 @@ f(x=1, y=2) # Error raised here
|
|||
|
||||
### Links
|
||||
* [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20unknown-argument)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L979)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1166)
|
||||
</details>
|
||||
|
||||
## `unresolved-attribute`
|
||||
|
@ -1204,11 +1381,20 @@ f(x=1, y=2) # Error raised here
|
|||
Checks for unresolved attributes.
|
||||
|
||||
### Why is this bad?
|
||||
Accessing an unbound attribute will raise an `AttributeError` at runtime. An unresolved attribute is not guaranteed to exist from the type alone, so this could also indicate that the object is not of the type that the user expects.
|
||||
Accessing an unbound attribute will raise an `AttributeError` at runtime.
|
||||
An unresolved attribute is not guaranteed to exist from the type alone,
|
||||
so this could also indicate that the object is not of the type that the user expects.
|
||||
|
||||
### Examples
|
||||
```python
|
||||
class A: ...
|
||||
|
||||
A().foo # AttributeError: 'A' object has no attribute 'foo'
|
||||
```
|
||||
|
||||
### Links
|
||||
* [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20unresolved-attribute)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1000)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1187)
|
||||
</details>
|
||||
|
||||
## `unresolved-import`
|
||||
|
@ -1222,12 +1408,17 @@ Accessing an unbound attribute will raise an `AttributeError` at runtime. An unr
|
|||
Checks for import statements for which the module cannot be resolved.
|
||||
|
||||
### Why is this bad?
|
||||
Importing a module that cannot be resolved will raise an `ImportError`
|
||||
Importing a module that cannot be resolved will raise a `ModuleNotFoundError`
|
||||
at runtime.
|
||||
|
||||
### Examples
|
||||
```python
|
||||
import foo # ModuleNotFoundError: No module named 'foo'
|
||||
```
|
||||
|
||||
### Links
|
||||
* [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20unresolved-import)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1013)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1209)
|
||||
</details>
|
||||
|
||||
## `unresolved-reference`
|
||||
|
@ -1251,7 +1442,7 @@ print(x) # NameError: name 'x' is not defined
|
|||
|
||||
### Links
|
||||
* [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20unresolved-reference)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1027)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1228)
|
||||
</details>
|
||||
|
||||
## `unsupported-bool-conversion`
|
||||
|
@ -1287,7 +1478,7 @@ b1 < b2 < b1 # exception raised here
|
|||
|
||||
### Links
|
||||
* [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20unsupported-bool-conversion)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L757)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L921)
|
||||
</details>
|
||||
|
||||
## `unsupported-operator`
|
||||
|
@ -1305,9 +1496,16 @@ the operands don't support the operator.
|
|||
Attempting to use an unsupported operator will raise a `TypeError` at
|
||||
runtime.
|
||||
|
||||
### Examples
|
||||
```python
|
||||
class A: ...
|
||||
|
||||
A() + A() # TypeError: unsupported operand type(s) for +: 'A' and 'A'
|
||||
```
|
||||
|
||||
### Links
|
||||
* [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20unsupported-operator)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1046)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1247)
|
||||
</details>
|
||||
|
||||
## `zero-stepsize-in-slice`
|
||||
|
@ -1331,7 +1529,7 @@ l[1:10:0] # ValueError: slice step cannot be zero
|
|||
|
||||
### Links
|
||||
* [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20zero-stepsize-in-slice)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1061)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1269)
|
||||
</details>
|
||||
|
||||
## `call-possibly-unbound-method`
|
||||
|
@ -1349,7 +1547,7 @@ Calling an unbound method will raise an `AttributeError` at runtime.
|
|||
|
||||
### Links
|
||||
* [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20call-possibly-unbound-method)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L102)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L103)
|
||||
</details>
|
||||
|
||||
## `invalid-ignore-comment`
|
||||
|
@ -1394,9 +1592,18 @@ Checks for possibly unbound attributes.
|
|||
### Why is this bad?
|
||||
Attempting to access an unbound attribute will raise an `AttributeError` at runtime.
|
||||
|
||||
### Examples
|
||||
```python
|
||||
class A:
|
||||
if b:
|
||||
c = 0
|
||||
|
||||
A.c # AttributeError: type object 'A' has no attribute 'c'
|
||||
```
|
||||
|
||||
### Links
|
||||
* [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20possibly-unbound-attribute)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L809)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L973)
|
||||
</details>
|
||||
|
||||
## `possibly-unbound-import`
|
||||
|
@ -1413,9 +1620,21 @@ Checks for imports of symbols that may be unbound.
|
|||
Importing an unbound module or name will raise a `ModuleNotFoundError`
|
||||
or `ImportError` at runtime.
|
||||
|
||||
### Examples
|
||||
```python
|
||||
## module.py
|
||||
import datetime
|
||||
|
||||
if datetime.date.today().weekday() != 6:
|
||||
a = 1
|
||||
|
||||
## main.py
|
||||
from module import a # ImportError: cannot import name 'a' from 'module'
|
||||
```
|
||||
|
||||
### Links
|
||||
* [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20possibly-unbound-import)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L822)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L995)
|
||||
</details>
|
||||
|
||||
## `redundant-cast`
|
||||
|
@ -1441,7 +1660,7 @@ cast(int, f()) # Redundant
|
|||
|
||||
### Links
|
||||
* [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20redundant-cast)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1118)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1340)
|
||||
</details>
|
||||
|
||||
## `undefined-reveal`
|
||||
|
@ -1458,11 +1677,13 @@ Checks for calls to `reveal_type` without importing it.
|
|||
Using `reveal_type` without importing it will raise a `NameError` at runtime.
|
||||
|
||||
### Examples
|
||||
TODO #14889
|
||||
```python
|
||||
reveal_type(1) # NameError: name 'reveal_type' is not defined
|
||||
```
|
||||
|
||||
### Links
|
||||
* [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20undefined-reveal)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L963)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1148)
|
||||
</details>
|
||||
|
||||
## `unknown-rule`
|
||||
|
@ -1519,7 +1740,7 @@ print(x) # NameError: name 'x' is not defined
|
|||
|
||||
### Links
|
||||
* [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20possibly-unresolved-reference)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L836)
|
||||
* [View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1021)
|
||||
</details>
|
||||
|
||||
## `unused-ignore-comment`
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[project]
|
||||
name = "ty"
|
||||
version = "0.0.0a8"
|
||||
version = "0.0.1a1"
|
||||
requires-python = ">=3.8"
|
||||
dependencies = []
|
||||
description = "An extremely fast Python type checker, written in Rust."
|
||||
|
|
2
ruff
2
ruff
|
@ -1 +1 @@
|
|||
Subproject commit 00f672a83b8435aa7e981eb6a8b4c42774ef2fbb
|
||||
Subproject commit f8890b70c35b2d05a8fa21958077de2aab5ba2ad
|
2
uv.lock
generated
2
uv.lock
generated
|
@ -762,7 +762,7 @@ wheels = [
|
|||
|
||||
[[package]]
|
||||
name = "ty"
|
||||
version = "0.0.0a8"
|
||||
version = "0.0.1a1"
|
||||
source = { editable = "." }
|
||||
|
||||
[package.dev-dependencies]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue