PyType (@NotNull PyExpression withExpression, @NotNull PyClassType withType, boolean isAsync, @NotNull TypeEvalContext context) { final PyClass cls = withType.getPyClass(); final PyFunction enter = cls.findMethodByName(isAsync ? PyNames.AENTER : PyNames.ENTER, true, context); if (enter != null) { final PyType enterType = getContextSensitiveType(enter, context, withExpression); if (enterType != null) { return isAsync ? Ref.deref(PyTypingTypeProvider.coroutineOrGeneratorElementType(enterType)) : enterType; } for (PyTypeProvider provider : PyTypeProvider.EP_NAME.getExtensionList()) { final PyType typeFromProvider = provider.getContextManagerVariableType(cls, withExpression, context); if (typeFromProvider != null) { return typeFromProvider; } } // Guess the return type of __enter__ return PyUnionType.createWeakType(withType); } return null; }