question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`get_*` functions must return something.

See original GitHub issue

Rule request

Thesis

Functions and methods with get_ prefix must return something (have return or yield in the body).

Reasoning

get_ function is expected to return what it promises to return. For example, get_user returns a user object. If it’s not so, it’s an error or a bad interface.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:19 (19 by maintainers)

github_iconTop GitHub Comments

3reactions
hhsdevcommented, Oct 21, 2020

@sobolevn Sorry to bother again.

The code is almost complete. But I wondered whether or not we should check every execution path a function can take to make sure it consistently returns a value .

Consider:

def get_foo():  # explicit return None; A-ok
    if some_condition:
        return 1
    return None

def get_bar():  # implicitly returns None if some_condition == False
    if some_condition:
        return 1

Should get_bar raise GetterWithoutReturnViolation?

1reaction
sobolevncommented, Oct 22, 2020

@hhsdev we already have a different rule that checks for consistent returns. This rule should check that we have at least one non-empty return.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Does a function always need to return something? - Python FAQ
Answer. NO, a function does not always have to have an explicit return statement. If the function doesn't need to provide any results ......
Read more >
The Python return Statement: Usage and Best Practices
In this step-by-step tutorial, you'll learn how to use the Python return statement when writing functions. Additionally, you'll cover some good programming ...
Read more >
Function return values - Learn web development | MDN
When the function completes (finishes running), it returns a value, which is a new string with the replacement made. In the code above,...
Read more >
Function must return a value - c++ - Stack Overflow
A declared std::string function should return a string and this is not the same as printing it on the screen, use return "something"...
Read more >
12.5. Returning a value from a function - Runestone Academy
You'll want to iterate over all the items in the list, each of the strings. As soon as you get to one name...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found