Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix custom root inspection #232

Merged
merged 1 commit into from
Jan 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
<idea-plugin url="https://github.com/koxudaxi/pydantic-pycharm-plugin" require-restart="true">
<id>com.koxudaxi.pydantic</id>
<name>Pydantic</name>
<version>0.1.18</version>
<version>0.1.19</version>
<vendor email="koaxudai@gmail.com">Koudai Aono @koxudaxi</vendor>
<change-notes><![CDATA[
<h2>version 0.1.19</h2>
<p>BugFixes</p>
<ul>
<li>Fix custom root inspection [#232]</li>
</ul>
<h2>version 0.1.18</h2>
<p>Features</p>
<ul>
Expand Down
5 changes: 3 additions & 2 deletions src/com/koxudaxi/pydantic/PydanticInspection.kt
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,11 @@ class PydanticInspection : PyInspection() {

private fun inspectCustomRootField(node: PyAssignmentStatement) {
val pyClass = getPyClassByAttribute(node) ?: return
if (!isPydanticModel(pyClass, true, myTypeEvalContext)) return
if (!isPydanticModel(pyClass, false, myTypeEvalContext)) return
val fieldName = (node.leftHandSideExpression as? PyTargetExpressionImpl)?.text ?: return
if (fieldName.startsWith('_')) return
pyClass.findClassAttribute("__root__", true, myTypeEvalContext) ?: return
val rootModel = pyClass.findClassAttribute("__root__", true, myTypeEvalContext)?.containingClass ?: return
if (!isPydanticModel(rootModel, false, myTypeEvalContext)) return
registerProblem(node,
"__root__ cannot be mixed with other fields", ProblemHighlightType.WARNING)
}
Expand Down