mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-76892 Conformance test failure: typeddicts_class_syntax.py
Check for unexpected __init_subclass__ parameter GitOrigin-RevId: bb6dd8975c14bf6758f6deaf73b6aead02003233
This commit is contained in:
committed by
intellij-monorepo-bot
parent
360699a959
commit
2273799954
@@ -1095,6 +1095,7 @@ INSP.typeddict.qualifiers.cannot.be.used.outside.typeddict.definition=''{0}'' ca
|
||||
INSP.typeddict.required.and.not.required.cannot.be.nested=Required[] and NotRequired[] cannot be nested
|
||||
INSP.typeddict.read.only.cannot.be.nested=ReadOnly[] cannot be nested
|
||||
INSP.typeddict.required.notrequired.must.have.exactly.one.type.argument=''{0}'' must have exactly one type argument
|
||||
INSP.typeddict.unexpected.argument.for.__init_subclass__.of.TypedDict=Unexpected argument ''{0}'' for __init_subclass__ of TypedDict
|
||||
|
||||
# PyTypeHintsInspection
|
||||
INSP.NAME.type.hints=Invalid type hints definitions and usages
|
||||
|
||||
+13
-4
@@ -69,14 +69,23 @@ class PyTypedDictInspection : PyInspection() {
|
||||
|
||||
override fun visitPyArgumentList(node: PyArgumentList) {
|
||||
if (node.parent is PyClass && PyTypedDictTypeProvider.isTypingTypedDictInheritor(node.parent as PyClass, myTypeEvalContext)) {
|
||||
val arguments = node.arguments
|
||||
for (argument in arguments) {
|
||||
for (argument in node.arguments) {
|
||||
val type = myTypeEvalContext.getType(argument)
|
||||
if (!isValidSuperclass(argument, type)) {
|
||||
registerProblem(argument, PyPsiBundle.message("INSP.typeddict.typeddict.cannot.inherit.from.non.typeddict.base.class"))
|
||||
}
|
||||
if (argument is PyKeywordArgument && argument.keyword == TYPED_DICT_TOTAL_PARAMETER && argument.valueExpression != null) {
|
||||
checkValidTotality(argument.valueExpression!!)
|
||||
if (argument is PyKeywordArgument) {
|
||||
val keyword = argument.keyword
|
||||
if (keyword == TYPED_DICT_TOTAL_PARAMETER) {
|
||||
val valueExpression = argument.valueExpression
|
||||
if (valueExpression != null) {
|
||||
checkValidTotality(valueExpression)
|
||||
}
|
||||
}
|
||||
else if (keyword != PyNames.METACLASS) {
|
||||
registerProblem(argument,
|
||||
PyPsiBundle.message("INSP.typeddict.unexpected.argument.for.__init_subclass__.of.TypedDict", keyword))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -242,6 +242,13 @@ public class PyTypedDictInspectionTest extends PyInspectionTestCase {
|
||||
"X = TypedDict('X', {'x': int}, total=<warning descr=\"Value of 'total' must be True or False\">1</warning>)");
|
||||
}
|
||||
|
||||
public void testUnexpectedInitClassArgument() {
|
||||
doTestByText("""
|
||||
from typing import TypedDict
|
||||
class A(TypedDict, <warning descr="Unexpected argument 'ab' for __init_subclass__ of TypedDict">ab=False</warning>):
|
||||
i: int""");
|
||||
}
|
||||
|
||||
public void testGetWithIncorrectKeyType() {
|
||||
doTestByText("""
|
||||
from typing import TypedDict
|
||||
|
||||
Reference in New Issue
Block a user