Page MenuHomePhabricator

Solve Inconsistent return statements
Open, LowPublic

Description

Introduction

Due to PEP8 [1] either all return statements in a function should return an expression, or none of them should.

# Correct:

def bar(x):
    if x < 0:
        return None
    return math.sqrt(x)
# Wrong:

def foo(x):
    if x >= 0:
        return math.sqrt(x)
   # implicit returns None here which should be explicit

def bar(x):
    if x < 0:
        return  # implicit returns None here which should be explicit
    return math.sqrt(x)

What to do

Issues to be solved can be found here:
https://deepsource.io/gh/xqt/pwb/issue/PYL-R1710/occurrences

Fix it by adding consistent return statements.
Please split your patch into smaller parts (no more than 20 methods at once) because it is heave to review a bulk of changed lines.

[1] https://peps.python.org/pep-0008/#programming-recommendations

Event Timeline

Xqt triaged this task as Low priority.Apr 11 2022, 3:23 PM

Change 808289 had a related patch set uploaded (by Vivian Rook; author: Vivian Rook):

[pywikibot/core@master] [IMPR] PEP8 updates

https://gerrit.wikimedia.org/r/808289

Change 808289 merged by jenkins-bot:

[pywikibot/core@master] [IMPR] PEP8 updates

https://gerrit.wikimedia.org/r/808289

Change 808918 had a related patch set uploaded (by Vivian Rook; author: Vivian Rook):

[pywikibot/core@master] [IMPR] PEP8 updates

https://gerrit.wikimedia.org/r/808918

Change 808918 merged by jenkins-bot:

[pywikibot/core@master] [IMPR] PEP8 updates

https://gerrit.wikimedia.org/r/808918

Change 809006 had a related patch set uploaded (by Vivian Rook; author: Vivian Rook):

[pywikibot/core@master] [IMPR] PEP8 updates

https://gerrit.wikimedia.org/r/809006

Change 809006 merged by jenkins-bot:

[pywikibot/core@master] [IMPR] PEP8 updates

https://gerrit.wikimedia.org/r/809006

Change 809615 had a related patch set uploaded (by Vivian Rook; author: Vivian Rook):

[pywikibot/core@master] [IMPR] PEP8 updates

https://gerrit.wikimedia.org/r/809615

Change 809615 merged by jenkins-bot:

[pywikibot/core@master] [IMPR] PEP8 updates

https://gerrit.wikimedia.org/r/809615

Change 812894 had a related patch set uploaded (by Vivian Rook; author: Vivian Rook):

[pywikibot/core@master] [IMPR] PEP8 updates

https://gerrit.wikimedia.org/r/812894

Change 812894 merged by jenkins-bot:

[pywikibot/core@master] [IMPR] PEP8 updates

https://gerrit.wikimedia.org/r/812894

Ayush_Anand3310 subscribed.

@Xqt I would like to work on this task. This is my first time contributing and I have understood what has to be fixed here but I don't know from where I can access this code and make changes in it?

Update: I got the github repo and have forked it and currently working to understand the codebase to make necessary changes to it.

@Ayush_Anand3310: You can use the GitHub repo to play with the code but be aware you cannot pull any changes to it because the GitHub repository is just a mirror. Patches have to be submitted to gerrit either via git commands, the web interface or the gerrit patch uploaded. Documentation can be found at mediawiki.org.

For the gerrit repo see
https://gerrit.wikimedia.org/r/admin/repos/pywikibot/core,general

@Aklapper ,I will go through the provided resources and work accordingly.

I have fixed the first 20 issues and will be soon submitting the first patch through gerrit.

Change 875430 had a related patch set uploaded (by Ayush Anand33; author: Ayush Anand33):

[pywikibot/core@master] Fixed Inconsistent return statements

https://gerrit.wikimedia.org/r/875430

@Xqt Should I submit a new commit for the changes I previously made with the preferred solution i.e without using "else"?

Change 875430 merged by jenkins-bot:

[pywikibot/core@master] [IMPR] PEP8 updates

https://gerrit.wikimedia.org/r/875430

@Xqt I am new to open source and would like to contribute more to Pywikibot. Can you suggest me some good resources for beginners from where I can learn more about it and start working on existing tasks?