From 79e3da543bef15156b1aa65bfc6e875d8ad15aac Mon Sep 17 00:00:00 2001 From: Andrey Vlasovskikh Date: Mon, 3 Feb 2014 18:03:10 +0400 Subject: [PATCH 1/2] Infer 'Iterable' as the type of tuples as default parameter values (PY-10967) It is too strict to infer 'tuple' as the type of default tuples, since they are often used as an immutable indicator, that a method expects a collection. --- .../com/jetbrains/python/psi/impl/PyNamedParameterImpl.java | 3 +++ .../PyTypeCheckerInspection/DefaultTupleParameter.py | 5 +++++ .../python/inspections/PyTypeCheckerInspectionTest.java | 5 +++++ 3 files changed, 13 insertions(+) create mode 100644 python/testData/inspections/PyTypeCheckerInspection/DefaultTupleParameter.py diff --git a/python/src/com/jetbrains/python/psi/impl/PyNamedParameterImpl.java b/python/src/com/jetbrains/python/psi/impl/PyNamedParameterImpl.java index 9c34062d2f08..dd94006b0c7e 100644 --- a/python/src/com/jetbrains/python/psi/impl/PyNamedParameterImpl.java +++ b/python/src/com/jetbrains/python/psi/impl/PyNamedParameterImpl.java @@ -238,6 +238,9 @@ public class PyNamedParameterImpl extends PyPresentableElementImpl Date: Mon, 3 Feb 2014 18:04:54 +0400 Subject: [PATCH 2/2] Fixed potential NPE --- .../python/psi/impl/PyNamedParameterImpl.java | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/python/src/com/jetbrains/python/psi/impl/PyNamedParameterImpl.java b/python/src/com/jetbrains/python/psi/impl/PyNamedParameterImpl.java index dd94006b0c7e..6ad33d60569e 100644 --- a/python/src/com/jetbrains/python/psi/impl/PyNamedParameterImpl.java +++ b/python/src/com/jetbrains/python/psi/impl/PyNamedParameterImpl.java @@ -252,15 +252,18 @@ public class PyNamedParameterImpl extends PyPresentableElementImpl entry : mapping.getPlainMappedParams().entrySet()) { - if (entry.getValue() == PyNamedParameterImpl.this) { - final PyExpression argument = entry.getKey(); - if (argument != null) { - final PyType type = context.getType(argument); - if (type != null) { - types.add(type); - return true; + final PyArgumentList argumentList = call.getArgumentList(); + if (argumentList != null) { + final CallArgumentsMapping mapping = argumentList.analyzeCall(resolveContext); + for (Map.Entry entry : mapping.getPlainMappedParams().entrySet()) { + if (entry.getValue() == PyNamedParameterImpl.this) { + final PyExpression argument = entry.getKey(); + if (argument != null) { + final PyType type = context.getType(argument); + if (type != null) { + types.add(type); + return true; + } } } }