ruff/crates/ty_python_semantic/src/semantic_index
David Peter b3c4005289
[ty] No boundness analysis for implicit instance attributes (#20128)
## Summary

With this PR, we stop performing boundness analysis for implicit
instance attributes:

```py
class C:
    def __init__(self):
        if False:   
            self.x = 1

C().x  # would previously show an error, with this PR we pretend the attribute exists
```

This PR is potentially just a temporary measure until we find a better
fix. But I have already invested a lot of time trying to find the root
cause of https://github.com/astral-sh/ty/issues/758 (and [this
example](https://github.com/astral-sh/ty/issues/758#issuecomment-3206108262),
which I'm not entirely sure is related) and I still don't understand
what is going on. This PR fixes the performance problems in both of
these problems (in a rather crude way).

The impact of the proposed change on the ecosystem is small, and the
three new diagnostics are arguably true positives (previously hidden
because we considered the code unreachable, based on e.g. `assert`ions
that depended on implicit instance attributes). So this seems like a
reasonable fix for now.

Note that we still support cases like these:

```py
class D:
    if False:  # or any other expression that statically evaluates to `False`
        x: int = 1

D().x  # still an error


class E:
    if False:  # or any other expression that statically evaluates to `False`
        def f(self):
            self.x = 1

E().x  # still an error
```

closes https://github.com/astral-sh/ty/issues/758

## Test Plan

Updated tests, benchmark results
2025-08-28 16:25:07 +02:00
..
builder Rename Red Knot (#17820) 2025-05-03 19:49:15 +02:00
use_def [ty] improve lazy scope place lookup (#19321) 2025-07-25 07:11:11 +00:00
ast_ids.rs [ty] Split ScopedPlaceId into ScopedSymbolId and ScopedMemberId (#19497) 2025-07-25 13:54:33 +02:00
builder.rs [ty] fix lazy snapshot sweeping in nested scopes (#19908) 2025-08-14 17:52:52 -07:00
definition.rs [ty] Strict validation of protocol members (#17750) 2025-08-19 22:45:41 +00:00
expression.rs [ty] Track heap usage of salsa structs (#19790) 2025-08-12 13:28:44 +02:00
member.rs [ty] Fix static assertion size check (#19814) 2025-08-07 13:38:16 -05:00
narrowing_constraints.rs [ty] Split ScopedPlaceId into ScopedSymbolId and ScopedMemberId (#19497) 2025-07-25 13:54:33 +02:00
place.rs Update Rust toolchain to 1.89 (#19807) 2025-08-07 18:21:50 +02:00
predicate.rs [ty] Track heap usage of salsa structs (#19790) 2025-08-12 13:28:44 +02:00
re_exports.rs [ty] Avoid overcounting shared memory usage (#19773) 2025-08-06 15:32:02 -04:00
reachability_constraints.rs [ty] No boundness analysis for implicit instance attributes (#20128) 2025-08-28 16:25:07 +02:00
scope.rs [ty] fix deferred name loading in PEP695 generic classes/functions (#19888) 2025-08-13 15:51:59 -07:00
symbol.rs [ty] more cases for the class body global fallback 2025-08-07 17:30:27 -07:00
use_def.rs [ty] No boundness analysis for implicit instance attributes (#20128) 2025-08-28 16:25:07 +02:00