mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-08-30 16:21:49 +07:00
to be able to access its scope class through getPyClass() and infer it
for `self` parameters, not having to replace it everywhere with
PyClassType.
This is similar to how other types with a "backing" PyClass are implemented, e.g.
PyTypedDictType delegates to PyClass(dict), PyNarrowedType delegates to PyClass(bool),
and so on.
It allowed removing special-casing for PySelfType and in many places treat
it identically to its scope class (that was previously inferred for `self`),
without converting back and forth between the two.
The only exceptions are places where we actually need to access the scope
class for error messages and code generation, e.g. in
PyUnresolvedReferencesInspection and its quick fixes.
Namely, extractScopeClassTypeIfNeeded and mutable `matchingScope`
were removed from PySelfType.
PyTypeChecker.match was simplified to consider PySelfType a subtype
of its scope PyClassType, itself compatible only with another PySelfType
(if a Self type is expected, only another Self type can be passed).
Since PySelf type now propagates through type inference freely,
not replaced with PyClassType when unnecessary, there is no need
to track where it's used. In particular, situations like
the following are properly handled because calling a method
returning Self on `self` still returns Self, but calling it
on an instance of the scope class returns PyClass for this class.
```
class C:
def copy(self):
return self
def m(self):
x: Self = self.copy() # ok
x: Self = C().copy() # expected Self@C, actual C
```
Few places in the type checker unification logic were updated to
take into account that the type of `self` for generic classes is
now just PySelfType, not PyCollectionType with unsubstituted type
arguments.
Among other benefits, this change allowed removing special-casing
for `object.__class__`. Now its type is just `type[Self]`
according to the type hints in Typeshed.
One unexpected place that required an update was resolveMember
and getVariants for PyCallableType.
Because the type `self` parameter is now PySelfType, which
implements PyTypeParameter, types of all unbound methods are now considered
generic types and hence go through the substitution process,
that replaces PyFunctionType with PyCallableTypeImpl (to be revised separately).
Surprisingly, PyCallableType didn't provide any of the attributes
of `types.FunctionType` or `types.UnboundMethodType` as PyFunctionType did.
Now the two callable types are in sync.
GitOrigin-RevId: eddb56f2fe1f2694554943fc64df288da6d84670