[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [kdev-python] duchain: Handle var/kwarg type hints correctly.
From: Sven Brauch <svenbrauch () googlemail ! com>
Date: 2012-09-26 10:55:16
Message-ID: 20120926105516.469C2A63F9 () git ! kde ! org
[Download RAW message or body]
Git commit 11452ff993ec2246deff975d0a57788f34f2fef1 by Sven Brauch.
Committed on 26/09/2012 at 12:55.
Pushed by brauch into branch 'master'.
Handle var/kwarg type hints correctly.
Should fix
BUG:307236
M +14 -8 duchain/declarationbuilder.cpp
M +2 -2 duchain/tests/pyduchaintest.cpp
http://commits.kde.org/kdev-python/11452ff993ec2246deff975d0a57788f34f2fef1
diff --git a/duchain/declarationbuilder.cpp b/duchain/declarationbuilder.cpp
index 4b05313..e79a2ff 100644
--- a/duchain/declarationbuilder.cpp
+++ b/duchain/declarationbuilder.cpp
@@ -319,17 +319,23 @@ template<typename T> T* \
DeclarationBuilder::visitVariableDeclaration(Identifier* if ( declarationOpened ) {
DeclarationBuilderBase::closeDeclaration();
}
- // check for argument type hints (those are created when calling functions)
- AbstractType::Ptr hints = Helper::extractTypeHints(dec->abstractType(), \
topContext());
- kDebug() << "Type Hints: " << hints->toString();
+
AbstractType::Ptr newType;
- if ( hints.cast<IndexedContainer>() || hints.cast<VariableLengthContainer>() \
) {
- // This only happens when the type hint is a tuple, which means the \
vararg/kwarg of a function is being processed.
- newType = hints;
+ if ( currentContext()->type() == DUContext::Function ) {
+ // check for argument type hints (those are created when calling \
functions) + AbstractType::Ptr hints = \
Helper::extractTypeHints(dec->abstractType(), topContext()); + kDebug() << \
"Type Hints: " << hints->toString(); + if ( hints.cast<IndexedContainer>() \
|| hints.cast<VariableLengthContainer>() ) { + // This only happens \
when the type hint is a tuple, which means the vararg/kwarg of a function is being \
processed. + newType = hints;
+ }
+ else {
+ newType = Helper::mergeTypes(hints, type, topContext());
+ kDebug() << "Resulting type: " << newType->toString();
+ }
}
else {
- newType = Helper::mergeTypes(hints, type, topContext());
- kDebug() << "Resulting type: " << newType->toString();
+ newType = type;
}
dec->setType(newType);
dec->setKind(KDevelop::Declaration::Instance);
diff --git a/duchain/tests/pyduchaintest.cpp b/duchain/tests/pyduchaintest.cpp
index 24f31a5..361b9de 100644
--- a/duchain/tests/pyduchaintest.cpp
+++ b/duchain/tests/pyduchaintest.cpp
@@ -471,8 +471,8 @@ void PyDUChainTest::testTypes_data()
QTest::newRow("tuple_loop") << "t = [(1, \"str\")]\nfor checkme, a in t: pass" \
<< "int";
- QTest::newRow("args_type") << "def myfun(*args): checkme = args\nmyfun(3)" << \
"tuple of string";
- QTest::newRow("kwarg_type") << "def myfun(**args): checkme = args\nmyfun(a=3)" \
<< "dict of string : int"; + QTest::newRow("args_type") << "def myfun(*args): \
return args[0]\ncheckme = myfun(3)" << "int"; + QTest::newRow("kwarg_type") << \
"def myfun(**args): return args[0]\ncheckme = myfun(a=3)" << "int";
QTest::newRow("tuple_listof") << "l = [(1, 2), (3, 4)]\ncheckme = l[1][0]" << \
"int";
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic