You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Good day, please help me to understand the implications and logic of that rule.
For example, I have a most basic getter function. Let's say it does a requests.get('url'). We want html content. Simple.
I did the simplest thing:
def get_html():
response = requests.get('google.com')
if response.code == 200:
return response.text
if response.code != 200:
return None
This goes against the rule.
Right before now, I was just doing the easiest if statement, to check if there is something returned and then continued on the happy path. Can't do it now, this goes against the rule.
...
text = gethtml()
if text:
print(text)
else:
sys.exit(0)
...
What improvement course is there?
Am I supposed to wrap that function call into try-except and rise an exception?
Is there some object I can return that signifies that the response was not 200?
Any cool other insight?
How it should be
I don't know!
Raising exceptions seems like heavy overengineering.
What's wrong
Good day, please help me to understand the implications and logic of that rule.
For example, I have a most basic getter function. Let's say it does a requests.get('url'). We want html content. Simple.
I did the simplest thing:
This goes against the rule.
Right before now, I was just doing the easiest if statement, to check if there is something returned and then continued on the happy path. Can't do it now, this goes against the rule.
What improvement course is there?
How it should be
I don't know!
Raising exceptions seems like heavy overengineering.
Flake8 version and plugins
7.0.0 (darglint: 1.8.1, flake8-bandit: 4.1.1, flake8-broken-line: 1.0.0, flake8-bugbear: 24.2.6, flake8-commas: 2.1.0, flake8-comprehensions: 3.14.0, flake8-debugger: 4.1.2, flake8-docstrings: 1.7.0, flake8-eradicate:
1.5.0, flake8-isort: 6.1.1, flake8-quotes: 3.4.0, flake8-rst-docstrings: 0.3.0, flake8-string-format: 0.3.0, mccabe: 0.7.0, pep8-naming: 0.13.3, pycodestyle: 2.11.1, pyflakes: 3.2.0, wemake-python-styleguide: 0.19.2)
CPython 3.12.0 on Windows
pip information
using pipx, can't tell.
OS information
Win11
The text was updated successfully, but these errors were encountered: