ruff/crates/ty_python_semantic/resources/mdtest
med1844 fd2cc37f90
[ty] Add decorator check for implicit attribute assignments (#18587)
## Summary

Previously, the checks for implicit attribute assignments didn't
properly account for method decorators. This PR fixes that by:

- Adding a decorator check in `implicit_instance_attribute`. This allows
it to filter out methods with mismatching decorators when analyzing
attribute assignments.
- Adding attribute search for implicit class attributes: if an attribute
can't be found directly in the class body, the
`ClassLiteral::own_class_member` function will now search in
classmethods.
- Adding `staticmethod`: it has been added into `KnownClass` and
together with the new decorator check, it will no longer expose
attributes when the assignment target name is the same as the first
method name.

If accepted, it should fix https://github.com/astral-sh/ty/issues/205
and https://github.com/astral-sh/ty/issues/207.

## Test Plan

This is tested with existing mdtest suites and is able to get most of
the TODO marks for implicit assignments in classmethods and
staticmethods removed.

However, there's one specific test case I failed to figure out how to
correctly resolve:


b279508bdc/crates/ty_python_semantic/resources/mdtest/attributes.md (L754-L755)

I tried to add `instance_member().is_unbound()` check in this [else
branch](b279508bdc/crates/ty_python_semantic/src/types/infer.rs (L3299-L3301))
but it causes tests with class attributes defined in class body to fail.
While it's possible to implicitly add `ClassVar` to qualifiers to make
this assignment fail and keep everything else passing, it doesn't feel
like the right solution.
2025-06-24 11:42:10 +02:00
..
annotations [ty] Fix panics when pulling types for various special forms that have the wrong number of parameters (#18642) 2025-06-17 10:40:50 +01:00
assignment [ty] Homogeneous and mixed tuples (#18600) 2025-06-20 18:23:54 -04:00
binary [ty] Homogeneous and mixed tuples (#18600) 2025-06-20 18:23:54 -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] add support for mapped union and intersection subscript loads (#18846) 2025-06-23 16:38:01 +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
conditional
declaration
diagnostics [ty] Surface matched overload diagnostic directly (#18452) 2025-06-20 08:36:49 +05:30
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] support del statement and deletion of except handler names (#18593) 2025-06-12 07:44:42 -07: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] Homogeneous and mixed tuples (#18600) 2025-06-20 18:23:54 -04:00
ide_support [ty] Minor tweaks to "list all members" docs and tests (#18388) 2025-05-30 13:36:57 -04:00
import Revert "[ty] Offer "Did you mean...?" suggestions for unresolved from imports and unresolved attributes (#18705)" (#18721) 2025-06-17 15:48:09 +01:00
literal [ty] Understand classes that inherit from subscripted Protocol[] as generic (#17832) 2025-05-09 17:39:15 +01:00
loops
narrow [ty] add support for mapped union and intersection subscript loads (#18846) 2025-06-23 16:38:01 +00:00
regression
scopes [ty] Minor change to builtins.md test (#18889) 2025-06-23 12:32:50 +02:00
shadowing
snapshots [ty] Surface matched overload diagnostic directly (#18452) 2025-06-20 08:36:49 +05:30
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] add support for mapped union and intersection subscript loads (#18846) 2025-06-23 16:38:01 +00:00
suppressions
type_compendium [ty] Homogeneous and mixed tuples (#18600) 2025-06-20 18:23:54 -04:00
type_of Update class literal display to use <class 'Foo'> style (#17889) 2025-05-06 20:11:25 -04:00
type_properties [ty] Fix mixed tuple subtyping (#18852) 2025-06-21 13:09:23 -07:00
type_qualifiers [ty] Fix panics when pulling types for ClassVar or Final parameterized with >1 argument (#18824) 2025-06-20 18:06:40 +01: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
attributes.md [ty] Add decorator check for implicit attribute assignments (#18587) 2025-06-24 11:42:10 +02: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] Report when a dataclass contains more than one KW_ONLY field (#18731) 2025-06-19 19:42:31 -07:00
decorators.md ty_python_semantic: add union type context to function call type errors 2025-05-09 13:40:51 -04:00
del.md [ty] support del statement and deletion of except handler names (#18593) 2025-06-12 07:44:42 -07:00
descriptor_protocol.md [ty] Add support for @staticmethods (#18809) 2025-06-20 10:38:17 +02:00
final.md
intersection_types.md [ty] Unify Type::is_subtype_of() and Type::is_assignable_to() (#18430) 2025-06-06 17:28:55 +00:00
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] 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 [ty] Add support for @staticmethods (#18809) 2025-06-20 10:38:17 +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] Unify Type::is_subtype_of() and Type::is_assignable_to() (#18430) 2025-06-06 17:28:55 +00:00
slots.md
statically_known_branches.md [ty] Reachability constraints (#18621) 2025-06-17 09:24:28 +02:00
sys_platform.md
sys_version_info.md
terminal_statements.md
type_api.md [ty] Fix panics when pulling types for various special forms that have the wrong number of parameters (#18642) 2025-06-17 10:40:50 +01:00
typed_dict.md
union_types.md
unpacking.md [ty] Avoid duplicate diagnostic in unpacking (#18897) 2025-06-24 07:49:44 +05:30
unreachable.md [ty] Reachability constraints (#18621) 2025-06-17 09:24:28 +02:00