ruff/crates/red_knot_python_semantic/resources/mdtest/annotations/deferred.md
David Peter 1e790d3885
[red-knot] Port 'deferred annotations' unit tests to Markdown (#15686)
## Summary

- Port "deferred annotations" unit tests to Markdown
- Port `implicit_global_in_function` unit test to Markdown
- Removed `resolve_method` and `local_inference` unit tests. These seem
  like relics from a time where type inference was in it's early stages.
  There is no way that these tests would fail today without lots of other
  things going wrong as well.

part of #13696
based on #15683 

## Test Plan

New MD tests for existing Rust unit tests.
2025-01-23 11:45:05 +00:00

862 B

Deferred annotations

Deferred annotations in stubs always resolve

def get_foo() -> Foo: ...
class Foo: ...
from mod import get_foo

reveal_type(get_foo())  # revealed: Foo

Deferred annotations in regular code fail

In (regular) source files, annotations are not deferred. This also tests that imports from __future__ that are not annotations are ignored.

from __future__ import with_statement as annotations

# error: [unresolved-reference]
def get_foo() -> Foo: ...

class Foo: ...

reveal_type(get_foo())  # revealed: Unknown

Deferred annotations in regular code with __future__.annotations

If __future__.annotations is imported, annotations are deferred.

from __future__ import annotations

def get_foo() -> Foo: ...

class Foo: ...

reveal_type(get_foo())  # revealed: Foo