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









share|improve this question






















  • 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










  • 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















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









share|improve this question






















  • 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










  • 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













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









share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 22 at 16:10









Laurici

62




62












  • 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










  • 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


















  • 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










  • 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
















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

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















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






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Trompette piccolo

Slow SSRS Report in dynamic grouping and multiple parameters

Simon Yates (cyclisme)