mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-02 14:52:01 +00:00

## Summary Resolves #15695, rework of #15704. This change modifies the Mdtests framework so that: * Paths must now be specified in a separate preceding line: `````markdown `a.py`: ```py x = 1 ``` ````` If the path of a file conflicts with its `lang`, an error will be thrown. * Configs are no longer accepted. The pattern still take them into account, however, to avoid "Unterminated code block" errors. * Unnamed files are now assigned unique, `lang`-respecting paths automatically. Additionally, all legacy usages have been updated. ## Test Plan Unit tests and Markdown tests. --------- Co-authored-by: Carl Meyer <carl@astral.sh>
861 B
861 B
Deferred annotations
Deferred annotations in stubs always resolve
mod.pyi
:
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