ruff/crates/ty_python_semantic/resources/mdtest
Shunsuke Shibayama 0858896bc4
[ty] type narrowing by attribute/subscript assignments (#18041)
## Summary

This PR partially solves https://github.com/astral-sh/ty/issues/164
(derived from #17643).

Currently, the definitions we manage are limited to those for simple
name (symbol) targets, but we expand this to track definitions for
attribute and subscript targets as well.

This was originally planned as part of the work in #17643, but the
changes are significant, so I made it a separate PR.
After merging this PR, I will reflect this changes in #17643.

There is still some incomplete work remaining, but the basic features
have been implemented, so I am publishing it as a draft PR.
Here is the TODO list (there may be more to come):
* [x] Complete rewrite and refactoring of documentation (removing
`Symbol` and replacing it with `Place`)
* [x] More thorough testing
* [x] Consolidation of duplicated code (maybe we can consolidate the
handling related to name, attribute, and subscript)

This PR replaces the current `Symbol` API with the `Place` API, which is
a concept that includes attributes and subscripts (the term is borrowed
from Rust).

## Test Plan

`mdtest/narrow/assignment.md` is added.

---------

Co-authored-by: David Peter <sharkdp@users.noreply.github.com>
Co-authored-by: Carl Meyer <carl@astral.sh>
2025-06-04 17:24:27 -07:00
..
annotations [ty] Support using legacy typing aliases for generic classes in type annotations (#18404) 2025-06-03 12:09:51 +01:00
assignment [ty] Add hint that PEP 604 union syntax is only available in 3.10+ (#18192) 2025-05-19 19:47:31 +02:00
binary [ty] Minor tweaks to "list all members" docs and tests (#18388) 2025-05-30 13:36:57 -04:00
boolean Revert "[ty] Better control flow for boolean expressions that are inside if (#18010)" (#18150) 2025-05-17 08:27:32 -04:00
boundness_declaredness Update class literal display to use `<class 'Foo'>` style (#17889) 2025-05-06 20:11:25 -04:00
call [ty] Argument type expansion for overload call evaluation (#18382) 2025-06-04 02:12:00 +00:00
class Update class literal display to use `<class 'Foo'>` style (#17889) 2025-05-06 20:11:25 -04:00
comparison [ty] Fix binary intersection comparison inference logic (#18266) 2025-05-23 12:55:17 +02:00
comprehensions Rename Red Knot (#17820) 2025-05-03 19:49:15 +02:00
conditional Rename Red Knot (#17820) 2025-05-03 19:49:15 +02:00
declaration Rename Red Knot (#17820) 2025-05-03 19:49:15 +02:00
diagnostics [ty] Don't warn `yield` not in function when `yield` is in function (#18008) 2025-05-21 18:16:25 +02:00
directives [ty] Fix normalization of unions containing instances parameterized with unions (#18112) 2025-05-14 22:48:33 -04:00
doc ty_python_semantic: add union type context to function call type errors 2025-05-09 13:40:51 -04:00
exception [ty] Raise `invalid-exception-caught` even when exception is not captured (#18202) 2025-05-19 18:13:34 -04:00
expression [ty] Treat lambda functions as instances of types.FunctionType (#18431) 2025-06-02 16:46:26 +01:00
function [ty] Add diagnosis for function with no return statement but with return type annotation (#18359) 2025-05-29 23:17:18 +00:00
generics [ty] Add meta-type tests for legavy TypeVars (#18453) 2025-06-04 07:44:44 +00:00
ide_support [ty] Minor tweaks to "list all members" docs and tests (#18388) 2025-05-30 13:36:57 -04:00
import [ty] Improve diagnostics if the user attempts to import a stdlib module that does not exist on their configured Python version (#18403) 2025-06-02 10:52:26 +00:00
literal [ty] Understand classes that inherit from subscripted `Protocol[]` as generic (#17832) 2025-05-09 17:39:15 +01:00
loops Rename Red Knot (#17820) 2025-05-03 19:49:15 +02:00
narrow [ty] type narrowing by attribute/subscript assignments (#18041) 2025-06-04 17:24:27 -07:00
regression Rename Red Knot (#17820) 2025-05-03 19:49:15 +02:00
scopes [ty] support accessing `__builtins__` global (#18118) 2025-05-15 22:01:38 +02:00
shadowing Rename Red Knot (#17820) 2025-05-03 19:49:15 +02:00
snapshots [ty] Only calculate information for unresolved-reference subdiagnostic if we know we'll emit the diagnostic (#18465) 2025-06-04 20:41:00 +01:00
stubs [ty] Do not carry the generic context of `Protocol` or `Generic` in the `ClassBase` enum (#17989) 2025-05-22 21:37:03 -04:00
subscript [ty] Do not carry the generic context of `Protocol` or `Generic` in the `ClassBase` enum (#17989) 2025-05-22 21:37:03 -04:00
suppressions Rename Red Knot (#17820) 2025-05-03 19:49:15 +02:00
type_compendium [ty] Type compendium (#18263) 2025-05-23 11:41:31 +02:00
type_of Update class literal display to use `<class 'Foo'>` style (#17889) 2025-05-06 20:11:25 -04:00
type_properties [ty] Ensure `Literal` types are considered assignable to anything their `Instance` supertypes are assignable to (#18351) 2025-06-01 16:39:56 +01:00
type_qualifiers Rename Red Knot (#17820) 2025-05-03 19:49:15 +02:00
unary Update class literal display to use `<class 'Foo'>` style (#17889) 2025-05-06 20:11:25 -04:00
with [ty] Add hint if async context manager is used in non-async with statement (#18299) 2025-05-26 21:34:47 +02:00
.mdformat.toml Rename Red Knot (#17820) 2025-05-03 19:49:15 +02:00
attributes.md [ty] type narrowing by attribute/subscript assignments (#18041) 2025-06-04 17:24:27 -07:00
cycle.md [ty] Add cycle handling for unpacking targets (#18078) 2025-05-13 21:27:48 +00:00
dataclass_transform.md [ty] Detect overloads decorated with `@dataclass_transform` (#17835) 2025-05-07 15:51:13 +02:00
dataclasses.md [ty] dataclasses: Allow using dataclasses.dataclass as a function. (#18440) 2025-06-03 09:50:29 -07:00
decorators.md ty_python_semantic: add union type context to function call type errors 2025-05-09 13:40:51 -04:00
descriptor_protocol.md [ty] type narrowing by attribute/subscript assignments (#18041) 2025-06-04 17:24:27 -07:00
final.md Rename Red Knot (#17820) 2025-05-03 19:49:15 +02:00
intersection_types.md Rename Red Knot (#17820) 2025-05-03 19:49:15 +02:00
invalid_syntax.md Rename Red Knot (#17820) 2025-05-03 19:49:15 +02:00
known_constants.md Rename Red Knot (#17820) 2025-05-03 19:49:15 +02:00
mdtest_config.md Rename Red Knot (#17820) 2025-05-03 19:49:15 +02:00
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] Implement implicit inheritance from `Generic[]` for PEP-695 generic classes (#18283) 2025-05-26 20:40:16 +01:00
named_tuple.md [ty] Add generic inference for dataclasses (#18443) 2025-06-03 09:59:43 -07:00
overloads.md Rename Red Knot (#17820) 2025-05-03 19:49:15 +02:00
pep695_type_aliases.md [ty] Support `typing.TypeAliasType` (#18156) 2025-05-19 16:36:49 +02:00
properties.md ty_python_semantic: add union type context to function call type errors 2025-05-09 13:40:51 -04:00
protocols.md [ty] Exclude members starting with `_abc_` from a protocol interface (#18467) 2025-06-04 20:34:09 +01:00
slots.md Rename Red Knot (#17820) 2025-05-03 19:49:15 +02:00
statically_known_branches.md Fix typos (#17988) 2025-05-09 14:57:14 -04:00
sys_platform.md Rename Red Knot (#17820) 2025-05-03 19:49:15 +02:00
sys_version_info.md Rename Red Knot (#17820) 2025-05-03 19:49:15 +02:00
terminal_statements.md Rename Red Knot (#17820) 2025-05-03 19:49:15 +02:00
type_api.md Update class literal display to use `<class 'Foo'>` style (#17889) 2025-05-06 20:11:25 -04:00
typed_dict.md Rename Red Knot (#17820) 2025-05-03 19:49:15 +02:00
union_types.md Rename Red Knot (#17820) 2025-05-03 19:49:15 +02:00
unpacking.md [ty] Add tests for empty list/tuple unpacking (#18451) 2025-06-04 02:40:26 +00:00
unreachable.md Rename Red Knot (#17820) 2025-05-03 19:49:15 +02:00