Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,22 @@ x = Foo()
reveal_type(x) # revealed: Foo
```

## Annotations are deferred by default in Python 3.14 and later

```toml
[environment]
python-version = "3.14"
```

```py
x: Foo

class Foo: ...

x = Foo()
reveal_type(x) # revealed: Foo
```

## Annotated assignments in stub files are inferred correctly

```pyi
Expand Down
7 changes: 5 additions & 2 deletions crates/ty_python_semantic/src/types/infer/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,9 +374,12 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> {
}

/// Are we currently inferring types in file with deferred types?
/// This is true for stub files and files with `__future__.annotations`
/// This is true for stub files, for files with `__future__.annotations`, and
/// by default for all source files in Python 3.14 and later.
fn defer_annotations(&self) -> bool {
self.index.has_future_annotations() || self.in_stub()
self.index.has_future_annotations()
|| self.in_stub()
|| Program::get(self.db()).python_version(self.db()) >= PythonVersion::PY314
}

/// Are we currently in a context where name resolution should be deferred
Expand Down
Loading