ruff/crates/ty_python_semantic/resources/mdtest/annotations
Shunsuke Shibayama 9dd666d677
[ty] fix global symbol lookup from eager scopes (#21317)
## Summary

cf. https://github.com/astral-sh/ruff/pull/20962

In the following code, `foo` in the comprehension was not reported as
unresolved:

```python
# error: [unresolved-reference] "Name `foo` used when not defined"
foo
foo = [
    # no error!
    # revealed: Divergent
    reveal_type(x) for _ in () for x in [foo]
]

baz = [
    # error: [unresolved-reference] "Name `baz` used when not defined"
    # revealed: Unknown
    reveal_type(x) for _ in () for x in [baz]
]
```

In fact, this is a more serious bug than it looks: for `foo`,
[`explicit_global_symbol` is
called](6cc3393ccd/crates/ty_python_semantic/src/types/infer/builder.rs (L8052)),
causing a symbol that should actually be `Undefined` to be reported as
being of type `Divergent`.

This PR fixes this bug. As a result, the code in
`mdtest/regression/pr_20962_comprehension_panics.md` no longer panics.

## Test Plan

`corpus\cyclic_symbol_in_comprehension.py` is added.
New tests are added in `mdtest/comprehensions/basic.md`.

---------

Co-authored-by: Micha Reiser <micha@reiser.io>
Co-authored-by: Carl Meyer <carl@astral.sh>
2025-11-12 10:15:51 -08:00
..
annotated.md [ty] Add support for Optional and Annotated in implicit type aliases (#21321) 2025-11-10 10:24:38 +01:00
any.md [ty] Use "cannot" consistently over "can not" (#21255) 2025-11-03 10:38:20 -05:00
callable.md [ty] Understand legacy and PEP 695 ParamSpec (#21139) 2025-11-06 11:14:40 -05:00
deferred.md [ty] fix global symbol lookup from eager scopes (#21317) 2025-11-12 10:15:51 -08:00
int_float_complex.md [ty] Improve disjointness inference for NominalInstanceTypes and SubclassOfTypes (#18864) 2025-06-24 20:27:37 +00:00
invalid.md [syntax-errors] Detect yield from inside async function (#20051) 2025-09-03 10:13:05 -04:00
literal.md [ty] Add support for Literals in implicit type aliases (#21296) 2025-11-07 17:46:55 +01:00
literal_string.md
never.md
new_types.md [ty] implement typing.NewType by adding Type::NewTypeInstance 2025-11-10 14:55:47 -08:00
optional.md
self.md [ty] Add support for properties that return Self (#21335) 2025-11-10 11:13:36 +01:00
starred.md [ty] Return Option<TupleType> from infer_tuple_type_expression (#19735) 2025-08-04 13:48:19 +01:00
stdlib_typing_aliases.md [ty] Fix bug where ty would think all types had an __mro__ attribute (#20995) 2025-10-27 11:19:12 +00:00
string.md [ty] Emit error for invalid binary operations in type expressions (#18991) 2025-06-30 10:06:01 +02:00
union.md [ty] Implicit type aliases: Support for PEP 604 unions (#21195) 2025-11-03 21:50:25 +01:00
unsupported_special_forms.md [ty] Understand legacy and PEP 695 ParamSpec (#21139) 2025-11-06 11:14:40 -05:00
unsupported_special_types.md Generalize special-casing for enums constructed with the functional syntax (#17885) 2025-05-06 11:02:55 +01:00
unsupported_type_qualifiers.md [ty] validate constructor call of TypedDict (#19810) 2025-08-25 14:45:52 +02:00