diff --git a/python/python-ast/src/com/jetbrains/python/ast/PyAstAsPattern.kt b/python/python-ast/src/com/jetbrains/python/ast/PyAstAsPattern.kt index 4dbe3beb542d..f6949f37c531 100644 --- a/python/python-ast/src/com/jetbrains/python/ast/PyAstAsPattern.kt +++ b/python/python-ast/src/com/jetbrains/python/ast/PyAstAsPattern.kt @@ -8,8 +8,8 @@ interface PyAstAsPattern : PyAstPattern { return requireNotNull(findChildByClass(PyAstPattern::class.java)) { "${this}: pattern cannot be null" } } - fun getTarget(): PyAstTargetExpression { - return requireNotNull(findChildByClass(PyAstTargetExpression::class.java)) { "${this}: target cannot be null" } + fun getTarget(): PyAstTargetExpression? { + return findChildByClass(PyAstTargetExpression::class.java) } override fun isIrrefutable(): Boolean { diff --git a/python/python-psi-impl/src/com/jetbrains/python/codeInsight/controlflow/PyControlFlowBuilder.java b/python/python-psi-impl/src/com/jetbrains/python/codeInsight/controlflow/PyControlFlowBuilder.java index 29e7c260f05c..5ab5fd879587 100644 --- a/python/python-psi-impl/src/com/jetbrains/python/codeInsight/controlflow/PyControlFlowBuilder.java +++ b/python/python-psi-impl/src/com/jetbrains/python/codeInsight/controlflow/PyControlFlowBuilder.java @@ -457,7 +457,9 @@ public class PyControlFlowBuilder extends PyRecursiveElementVisitor { // So no need to create an additional fail edge myBuilder.startNode(node); node.acceptChildren(this); - myPatternBindingNames.add(node.getTarget().getName()); + if (node.getTarget() != null) { + myPatternBindingNames.add(node.getTarget().getName()); + } myBuilder.updatePendingElementScope(node, node.getParent()); }