mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-08 15:09:39 +07:00
Infer correct type for docstrings (PY-35885)
GitOrigin-RevId: 2994a2e312611b038c72ec18abb2cd96880213e9
This commit is contained in:
committed by
intellij-monorepo-bot
parent
39c4f75298
commit
161a28d32a
@@ -165,6 +165,9 @@ public class PyStringLiteralExpressionImpl extends PyElementImpl implements PySt
|
||||
// f-strings can't have "b" prefix so they are always unicode
|
||||
return builtinCache.getUnicodeType(languageLevel);
|
||||
}
|
||||
else if (firstNode.getElementType() == PyTokenTypes.DOCSTRING) {
|
||||
return builtinCache.getStrType();
|
||||
}
|
||||
|
||||
if (file != null) {
|
||||
final IElementType type = PythonHighlightingLexer.convertStringType(firstNode.getElementType(),
|
||||
|
||||
@@ -1133,6 +1133,15 @@ public class Py3TypeTest extends PyTestCase {
|
||||
"expr = f'foo'");
|
||||
}
|
||||
|
||||
// PY-35885
|
||||
public void testFunctionDunderDoc() {
|
||||
doTest("str",
|
||||
"def example():\n" +
|
||||
" \"\"\"Example Docstring\"\"\"\n" +
|
||||
" return 0\n" +
|
||||
"expr = example.__doc__");
|
||||
}
|
||||
|
||||
private void doTest(final String expectedType, final String text) {
|
||||
myFixture.configureByText(PythonFileType.INSTANCE, text);
|
||||
final PyExpression expr = myFixture.findElementByText("expr", PyExpression.class);
|
||||
|
||||
@@ -3768,6 +3768,15 @@ public class PyTypeTest extends PyTestCase {
|
||||
);
|
||||
}
|
||||
|
||||
// PY-35885
|
||||
public void testFunctionDunderDoc() {
|
||||
doTest("str",
|
||||
"def example():\n" +
|
||||
" \"\"\"Example Docstring\"\"\"\n" +
|
||||
" return 0\n" +
|
||||
"expr = example.__doc__");
|
||||
}
|
||||
|
||||
private static List<TypeEvalContext> getTypeEvalContexts(@NotNull PyExpression element) {
|
||||
return ImmutableList.of(TypeEvalContext.codeAnalysis(element.getProject(), element.getContainingFile()).withTracing(),
|
||||
TypeEvalContext.userInitiated(element.getProject(), element.getContainingFile()).withTracing());
|
||||
|
||||
Reference in New Issue
Block a user