ruff
afa6bcbd - [ty] Preserve gradual behavior for explicit Any subclasses (#26034)

Commit
42 days ago
[ty] Preserve gradual behavior for explicit Any subclasses (#26034) ## Summary In https://github.com/astral-sh/ty/issues/1686#issuecomment-4343186815, we decided the following: > We discussed this internally and our current plan is to treat instances of `class Mock(Any): ...` as if they were of type `Mock & Any`. This would enable the use case here, and still give accurate types (and things like auto-completion) for actual attributes on `Mock`. > > Note that this will mean that we treat `class C(Any): ...` differently from `class C(SomethingOfTypeAnyOrUnknown): ...`. The latter would still be a normal class with a dynamic base, i.e. an instance of that class would not be assignable to arbitrary types. As such, instances of classes that explicitly inherit from `Any` now retain their nominal type and precise declared members while remaining assignable to arbitrary types, including`Final` and `Literal` types: ```python from typing import Any, final class Mock(Any): def method(self) -> int: ... @final class FinalClass: ... value: FinalClass = Mock() result: int = Mock().method() ``` Closes https://github.com/astral-sh/ty/issues/1686.
Author
Parents
Loading