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:
Daniil Kalinin
2021-12-13 18:39:22 +03:00
committed by intellij-monorepo-bot
parent c1c97dde02
commit dda63f05d8
2 changed files with 34 additions and 9 deletions

View File

@@ -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()
}