-
-
Notifications
You must be signed in to change notification settings - Fork 383
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Early return should not take return None
form when it is not required
#2151
Comments
so we need just change that from |
@siddharth1704 yes! I think that we can formulate this rule as:
|
@sobolevn if we have returned none in a function, it means it's meant for later use, since we don't have the value to return, we do return none? please correct me if I'm wrong. |
i would like to contribute to this, please assign me. |
We allow: def some():
if condition:
return None
return other We don't allow: def some():
if condition:
return None
print() |
@sobolevn can you tell me the process to contribute? |
You should probably start with learning what
|
hey @sobolevn I understood the concept(thesis) and I did comprehend how |
Ok, we also need to take a closer look at: def some_funct():
if first_cond:
return None
if second_cond:
return None
print('a') I would re-formulate the rule as: if all function @DhirajChauhan40 is_all_none = (
issubclass(returning_type, ast.Return) and
has_values and
all(
ret_node.value.value is None
for ret_node in return_nodes
if isinstance(ret_node.value, (compat.nodes.Constant, ast.NameConstant))
)
)
if is_all_none:
self.add_violation(...) You can put it here: You would still have to:
|
@sobolevn |
@sobolevn so i was tryna run the file and I got this error in confest.py inside tests folder
|
Are you running pythno3.9? |
yes after installing the 3.9 version, it was working thanks! |
Hey @sobolevn i have added my violation to
but In
|
Can you please open a PR? |
yes sure |
How should I write the following code without noqa? def files_key(self, package_file: PackageFile) -> Optional[str]: # noqa: WPS324
"""Get files key, to upload to. If None, uploaded as body.
Args:
package_file: Source package file.
Returns:
The files key, or None.
"""
return None # noqa: WPS324 This function is overriden in child classes. NB: Using
See https://gitlab.com/gitlabracadabra/gitlabracadabra/-/merge_requests/233 |
def files_key(self, package_file: PackageFile) -> Optional[str]: # noqa: WPS324
"""Get files key, to upload to. If None, uploaded as body.
Args:
package_file: Source package file.
Returns:
The files key, or None.
""" 🙂 |
@sobolevn Now I have:
|
Hm, can you please open a new bug? Looks like when we have |
Rule request
Thesis
Right now this code:
passes our style check. Note
return None
part there. It is the onlyreturn
. And it means thatNone
part is not required.Moreover, it should not be allowed
. Simple early returns must be just
return`.The text was updated successfully, but these errors were encountered: