ruff/crates/ty_python_semantic/resources/mdtest
Brent Westbrook 57bf7dfbd9
[ty] Implement global handling and load-before-global-declaration syntax error (#17637)
Summary
--

This PR resolves both the typing-related and syntax error TODOs added in
#17563 by tracking a set of `global` bindings for each scope. As
discussed below, we avoid the additional AST traversal from ruff by
collecting `Name`s from `global` statements while building the semantic
index and emit a syntax error if the `Name` is already bound in the
current scope at the point of the `global` statement. This has the
downside of separating the error from the `SemanticSyntaxChecker`, but I
plan to explore using this approach in the `SemanticSyntaxChecker`
itself as a follow-up. It seems like this may be a better approach for
ruff as well.

Test Plan
--

Updated all of the related mdtests to remove the TODOs (and add quotes I
forgot on the messages).

There is one remaining TODO, but it requires `nonlocal` support, which
isn't even incorporated into the `SemanticSyntaxChecker` yet.

---------

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Co-authored-by: Carl Meyer <carl@astral.sh>
2025-05-08 10:30:04 -04:00
..
annotations Support typing.Self in methods (#17689) 2025-05-07 15:58:00 -07:00
assignment
binary [ty] Add missing bitwise-operator branches for boolean and integer arithmetic (#17949) 2025-05-08 14:10:35 +01:00
boolean
boundness_declaredness Update class literal display to use <class 'Foo'> style (#17889) 2025-05-06 20:11:25 -04:00
call Support typing.Self in methods (#17689) 2025-05-07 15:58:00 -07:00
class Update class literal display to use <class 'Foo'> style (#17889) 2025-05-06 20:11:25 -04:00
comparison
comprehensions
conditional
declaration
diagnostics [ty] Implement global handling and load-before-global-declaration syntax error (#17637) 2025-05-08 10:30:04 -04:00
directives
doc
exception Update class literal display to use <class 'Foo'> style (#17889) 2025-05-06 20:11:25 -04:00
expression Update class literal display to use <class 'Foo'> style (#17889) 2025-05-06 20:11:25 -04:00
function [ty] Recognise functions containing yield from expressions as being generator functions (#17930) 2025-05-07 23:29:44 +01:00
generics [ty] Check base classes when determining subtyping etc for generic aliases (#17927) 2025-05-07 15:21:11 -04:00
import [ty] Add support for __all__ (#17856) 2025-05-07 21:42:42 +05:30
literal
loops
narrow Update class literal display to use <class 'Foo'> style (#17889) 2025-05-06 20:11:25 -04:00
regression
scopes [ty] Implement global handling and load-before-global-declaration syntax error (#17637) 2025-05-08 10:30:04 -04:00
shadowing
snapshots [ty] Recognise functions containing yield from expressions as being generator functions (#17930) 2025-05-07 23:29:44 +01:00
stubs Update class literal display to use <class 'Foo'> style (#17889) 2025-05-06 20:11:25 -04:00
subscript Update class literal display to use <class 'Foo'> style (#17889) 2025-05-06 20:11:25 -04:00
suppressions
type_of Update class literal display to use <class 'Foo'> style (#17889) 2025-05-06 20:11:25 -04:00
type_properties [ty] Check base classes when determining subtyping etc for generic aliases (#17927) 2025-05-07 15:21:11 -04:00
type_qualifiers
unary Update class literal display to use <class 'Foo'> style (#17889) 2025-05-06 20:11:25 -04:00
with
.mdformat.toml
attributes.md Update class literal display to use <class 'Foo'> style (#17889) 2025-05-06 20:11:25 -04:00
cycle.md [ty] add cycle handling for FunctionType::signature query (#17833) 2025-05-05 12:12:38 -07:00
dataclass_transform.md [ty] Detect overloads decorated with @dataclass_transform (#17835) 2025-05-07 15:51:13 +02:00
dataclasses.md Update class literal display to use <class 'Foo'> style (#17889) 2025-05-06 20:11:25 -04:00
decorators.md [ty] Specialize bound methods and nominal instances (#17865) 2025-05-05 17:17:36 -04:00
descriptor_protocol.md Update class literal display to use <class 'Foo'> style (#17889) 2025-05-06 20:11:25 -04:00
final.md
intersection_types.md
invalid_syntax.md
known_constants.md
mdtest_config.md
mdtest_custom_typeshed.md [ty] Fix duplicate diagnostics for unresolved module when an import from statement imports multiple members (#17886) 2025-05-06 12:37:10 +01:00
metaclass.md Update class literal display to use <class 'Foo'> style (#17889) 2025-05-06 20:11:25 -04:00
mro.md [ty] Improve UX for [duplicate-base] diagnostics (#17914) 2025-05-07 15:27:37 +00:00
named_tuple.md
overloads.md
pep695_type_aliases.md
properties.md
protocols.md [ty] Protocols: Fixpoint iteration for fully-static check (#17880) 2025-05-07 08:55:21 +02:00
slots.md
statically_known_branches.md
sys_platform.md
sys_version_info.md
terminal_statements.md
type_api.md Update class literal display to use <class 'Foo'> style (#17889) 2025-05-06 20:11:25 -04:00
typed_dict.md
union_types.md
unpacking.md
unreachable.md