Function does not return expected instance
up vote
1
down vote
favorite
I have a very specific problem in my code and I just can't figure it out why.
select_desire_tool() returns None.
It seems that when it arrives at return self._associated_instance(value), somehow it finishes some process in the else statement of the for loop and the supposed returned instance is lost.
why is that?
Return specific instance
def _associated_instance(self, argument):
if RegionConstants.SETTINGS == argument:
return Settings()
else:
test.fail("No such instance found.")
raise
## Clicks on desired map tools option
# @param[in] self The self object pointer.
# @param[in] value Map tools option to be selected
# @return specific class instance class instance
def select_desire_tool(self, value):
items_from_list = self.items
for item in items_from_list:
if item.name == value:
while True:
try:
item.click_button()
return self._associated_instance(value)
except LookupError:
Base().Scrollbar().scroll_down()
else:
if not Base().Scrollbar().at_y_end:
Base().Scrollbar().scroll_down()
self.select_desire_tool(value)
else:
test.fail("Option was not found in map tools")
raise
python
add a comment |
up vote
1
down vote
favorite
I have a very specific problem in my code and I just can't figure it out why.
select_desire_tool() returns None.
It seems that when it arrives at return self._associated_instance(value), somehow it finishes some process in the else statement of the for loop and the supposed returned instance is lost.
why is that?
Return specific instance
def _associated_instance(self, argument):
if RegionConstants.SETTINGS == argument:
return Settings()
else:
test.fail("No such instance found.")
raise
## Clicks on desired map tools option
# @param[in] self The self object pointer.
# @param[in] value Map tools option to be selected
# @return specific class instance class instance
def select_desire_tool(self, value):
items_from_list = self.items
for item in items_from_list:
if item.name == value:
while True:
try:
item.click_button()
return self._associated_instance(value)
except LookupError:
Base().Scrollbar().scroll_down()
else:
if not Base().Scrollbar().at_y_end:
Base().Scrollbar().scroll_down()
self.select_desire_tool(value)
else:
test.fail("Option was not found in map tools")
raise
python
Is theelse
for thefor
loop or theif
statement?for: else:
orif: else:
?
– C.Nivs
Nov 22 at 16:21
We need details of the function call, but the function you have here certainly won't reach thatreturn
statement for all possible input parameters - and if it doesn't, then it will implicitly returnNone
– Robin Zigmond
Nov 22 at 16:34
You should add logging or debug printing. Code looks complicated for it purpose. Again,else
statement offor
loop looks like a mistype. And even if not, it's unnecessary as there is nobreak
in the loop. Another possible mistake is that when you call recursivelyself.select_desire_tool(value)
you don't return what it returns, i.e. it should bereturn self.select_desire_tool(value)
.
– George Sovetov
Nov 22 at 18:09
You need to fix the if : else indentation.
– Srikan
Nov 22 at 18:50
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I have a very specific problem in my code and I just can't figure it out why.
select_desire_tool() returns None.
It seems that when it arrives at return self._associated_instance(value), somehow it finishes some process in the else statement of the for loop and the supposed returned instance is lost.
why is that?
Return specific instance
def _associated_instance(self, argument):
if RegionConstants.SETTINGS == argument:
return Settings()
else:
test.fail("No such instance found.")
raise
## Clicks on desired map tools option
# @param[in] self The self object pointer.
# @param[in] value Map tools option to be selected
# @return specific class instance class instance
def select_desire_tool(self, value):
items_from_list = self.items
for item in items_from_list:
if item.name == value:
while True:
try:
item.click_button()
return self._associated_instance(value)
except LookupError:
Base().Scrollbar().scroll_down()
else:
if not Base().Scrollbar().at_y_end:
Base().Scrollbar().scroll_down()
self.select_desire_tool(value)
else:
test.fail("Option was not found in map tools")
raise
python
I have a very specific problem in my code and I just can't figure it out why.
select_desire_tool() returns None.
It seems that when it arrives at return self._associated_instance(value), somehow it finishes some process in the else statement of the for loop and the supposed returned instance is lost.
why is that?
Return specific instance
def _associated_instance(self, argument):
if RegionConstants.SETTINGS == argument:
return Settings()
else:
test.fail("No such instance found.")
raise
## Clicks on desired map tools option
# @param[in] self The self object pointer.
# @param[in] value Map tools option to be selected
# @return specific class instance class instance
def select_desire_tool(self, value):
items_from_list = self.items
for item in items_from_list:
if item.name == value:
while True:
try:
item.click_button()
return self._associated_instance(value)
except LookupError:
Base().Scrollbar().scroll_down()
else:
if not Base().Scrollbar().at_y_end:
Base().Scrollbar().scroll_down()
self.select_desire_tool(value)
else:
test.fail("Option was not found in map tools")
raise
python
python
asked Nov 22 at 16:10
Laurici
62
62
Is theelse
for thefor
loop or theif
statement?for: else:
orif: else:
?
– C.Nivs
Nov 22 at 16:21
We need details of the function call, but the function you have here certainly won't reach thatreturn
statement for all possible input parameters - and if it doesn't, then it will implicitly returnNone
– Robin Zigmond
Nov 22 at 16:34
You should add logging or debug printing. Code looks complicated for it purpose. Again,else
statement offor
loop looks like a mistype. And even if not, it's unnecessary as there is nobreak
in the loop. Another possible mistake is that when you call recursivelyself.select_desire_tool(value)
you don't return what it returns, i.e. it should bereturn self.select_desire_tool(value)
.
– George Sovetov
Nov 22 at 18:09
You need to fix the if : else indentation.
– Srikan
Nov 22 at 18:50
add a comment |
Is theelse
for thefor
loop or theif
statement?for: else:
orif: else:
?
– C.Nivs
Nov 22 at 16:21
We need details of the function call, but the function you have here certainly won't reach thatreturn
statement for all possible input parameters - and if it doesn't, then it will implicitly returnNone
– Robin Zigmond
Nov 22 at 16:34
You should add logging or debug printing. Code looks complicated for it purpose. Again,else
statement offor
loop looks like a mistype. And even if not, it's unnecessary as there is nobreak
in the loop. Another possible mistake is that when you call recursivelyself.select_desire_tool(value)
you don't return what it returns, i.e. it should bereturn self.select_desire_tool(value)
.
– George Sovetov
Nov 22 at 18:09
You need to fix the if : else indentation.
– Srikan
Nov 22 at 18:50
Is the
else
for the for
loop or the if
statement? for: else:
or if: else:
?– C.Nivs
Nov 22 at 16:21
Is the
else
for the for
loop or the if
statement? for: else:
or if: else:
?– C.Nivs
Nov 22 at 16:21
We need details of the function call, but the function you have here certainly won't reach that
return
statement for all possible input parameters - and if it doesn't, then it will implicitly return None
– Robin Zigmond
Nov 22 at 16:34
We need details of the function call, but the function you have here certainly won't reach that
return
statement for all possible input parameters - and if it doesn't, then it will implicitly return None
– Robin Zigmond
Nov 22 at 16:34
You should add logging or debug printing. Code looks complicated for it purpose. Again,
else
statement of for
loop looks like a mistype. And even if not, it's unnecessary as there is no break
in the loop. Another possible mistake is that when you call recursively self.select_desire_tool(value)
you don't return what it returns, i.e. it should be return self.select_desire_tool(value)
.– George Sovetov
Nov 22 at 18:09
You should add logging or debug printing. Code looks complicated for it purpose. Again,
else
statement of for
loop looks like a mistype. And even if not, it's unnecessary as there is no break
in the loop. Another possible mistake is that when you call recursively self.select_desire_tool(value)
you don't return what it returns, i.e. it should be return self.select_desire_tool(value)
.– George Sovetov
Nov 22 at 18:09
You need to fix the if : else indentation.
– Srikan
Nov 22 at 18:50
You need to fix the if : else indentation.
– Srikan
Nov 22 at 18:50
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53434759%2ffunction-does-not-return-expected-instance%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Is the
else
for thefor
loop or theif
statement?for: else:
orif: else:
?– C.Nivs
Nov 22 at 16:21
We need details of the function call, but the function you have here certainly won't reach that
return
statement for all possible input parameters - and if it doesn't, then it will implicitly returnNone
– Robin Zigmond
Nov 22 at 16:34
You should add logging or debug printing. Code looks complicated for it purpose. Again,
else
statement offor
loop looks like a mistype. And even if not, it's unnecessary as there is nobreak
in the loop. Another possible mistake is that when you call recursivelyself.select_desire_tool(value)
you don't return what it returns, i.e. it should bereturn self.select_desire_tool(value)
.– George Sovetov
Nov 22 at 18:09
You need to fix the if : else indentation.
– Srikan
Nov 22 at 18:50