mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-40313 Fix for "Python string literals in Markdown documents are treated as 'bytes' for type-checking purposes"
(cherry picked from commit 2a423d0fbbf4524844c52189a6be4cf9f43f7407) IJ-CR-18590 GitOrigin-RevId: 33739b79cb8bc76c447d69080940985f431641dc
This commit is contained in:
committed by
intellij-monorepo-bot
parent
c1c97dde02
commit
dda63f05d8
@@ -1,6 +1,7 @@
|
||||
package com.jetbrains.python.markdown
|
||||
|
||||
import com.jetbrains.python.fixtures.PyTestCase
|
||||
import com.jetbrains.python.inspections.PyTypeCheckerInspection
|
||||
|
||||
/**
|
||||
* Tests for [PyCodeFenceLanguageProvider].
|
||||
@@ -127,6 +128,28 @@ class PyCodeFenceTest : PyTestCase() {
|
||||
assertContainsElements(lookupStrings, "doctest", "python", "pycon")
|
||||
}
|
||||
|
||||
//PY-40313
|
||||
fun testStringsAndBytesResolvedCorrectlyInPythonFragment() {
|
||||
myFixture.configureByText("a.md", """
|
||||
```python
|
||||
def expect_str(s:str):
|
||||
pass
|
||||
|
||||
def expect_bytes(b:bytes):
|
||||
pass
|
||||
|
||||
# Should not warn
|
||||
expect_str("abc")
|
||||
|
||||
# Should warn
|
||||
expect_bytes(<warning descr="Expected type 'bytes', got 'str' instead">"abc"</warning>)
|
||||
```
|
||||
""".trimIndent())
|
||||
myFixture.enableInspections(PyTypeCheckerInspection::class.java);
|
||||
myFixture.checkHighlighting(true, false, true);
|
||||
assertSdkRootsNotParsed(myFixture.file)
|
||||
}
|
||||
|
||||
private val lookupStrings: List<String>
|
||||
get() = myFixture.lookupElementStrings ?: emptyList()
|
||||
}
|
||||
|
||||
+11
-9
@@ -175,18 +175,20 @@ public class PyStringLiteralExpressionImpl extends PyElementImpl implements PySt
|
||||
else if (firstNode.getElementType() == PyTokenTypes.DOCSTRING) {
|
||||
return builtinCache.getStrType();
|
||||
}
|
||||
else if (((PyStringElement)firstNode).isBytes()) {
|
||||
return builtinCache.getBytesType(languageLevel);
|
||||
}
|
||||
|
||||
if (file != null) {
|
||||
final IElementType type = PythonHighlightingLexer.convertStringType(firstNode.getElementType(),
|
||||
firstNode.getText(),
|
||||
languageLevel,
|
||||
file.hasImportFromFuture(FutureFeature.UNICODE_LITERALS));
|
||||
if (PyTokenTypes.UNICODE_NODES.contains(type)) {
|
||||
return builtinCache.getUnicodeType(languageLevel);
|
||||
}
|
||||
final IElementType type = PythonHighlightingLexer.convertStringType(firstNode.getElementType(),
|
||||
firstNode.getText(),
|
||||
languageLevel,
|
||||
(file != null &&
|
||||
file.hasImportFromFuture(FutureFeature.UNICODE_LITERALS)));
|
||||
if (PyTokenTypes.UNICODE_NODES.contains(type)) {
|
||||
return builtinCache.getUnicodeType(languageLevel);
|
||||
}
|
||||
}
|
||||
return builtinCache.getBytesType(languageLevel);
|
||||
return builtinCache.getStrType();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user