-
-
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
Allow to return None without noqa #2323
Comments
So, I've got back to this! Sorry for the late response. I cannot reproduce this at all: from typing import Optional
def files_key(package_file) -> Optional[str]:
"""
Get files key, to upload to. If None, uploaded as body.
Args:
package_file: Source package file.
Returns:
The files key, or None.
""" This code is perfectly fine:
I am going to close this as non-repro. Please, feel free to reopen if you have a working reporduction 🙂 |
@sobolevn I can reproduce with: def files_key(self, package_file: PackageFile) -> Optional[str]:
"""Get files key, to upload to. If None, uploaded as body.
Args:
package_file: Source package file.
Returns:
The files key, or None.
""" $ tox -e pep8
GLOB sdist-make: /home/mathieu/git/gitlab.com/gitlabracadabra/gitlabracadabra/setup.py
pep8 create: /home/mathieu/git/gitlab.com/gitlabracadabra/gitlabracadabra/.tox/pep8
pep8 installdeps: -rpep8-requirements.txt
pep8 inst: /home/mathieu/git/gitlab.com/gitlabracadabra/gitlabracadabra/.tox/.tmp/package/1/gitlabracadabra-1.4.0a0.zip
pep8 installed: astor==0.8.1,astroid==2.9.3,attrs==21.4.0,bandit==1.7.2,certifi==2021.10.8,cffi==1.15.0,charset-normalizer==2.0.11,darglint==1.8.1,Deprecated==1.2.13,docutils==0.18.1,eradicate==2.0.0,flake8==3.9.2,flake8-assertive==1.3.0,flake8-bandit==2.1.2,flake8-blind-except==0.2.0,flake8-broken-line==0.3.0,flake8-bugbear==21.11.29,flake8-builtins==1.5.3,flake8-commas==2.1.0,flake8-comprehensions==3.7.0,flake8-debugger==4.0.0,flake8-deprecated==1.3,flake8-docstrings==1.6.0,flake8-eradicate==1.2.0,flake8-isort==4.1.1,flake8-logging-format==0.6.0,flake8-polyfill==1.0.2,flake8-quotes==3.3.1,flake8-rst-docstrings==0.2.5,flake8-string-format==0.3.0,flake8-tidy-imports==4.5.0,flake8-tuple==0.4.1,gitdb==4.0.9,gitlabracadabra @ file:///home/mathieu/git/gitlab.com/gitlabracadabra/gitlabracadabra/.tox/.tmp/package/1/gitlabracadabra-1.4.0a0.zip,GitPython==3.1.26,html5lib==1.1,idna==3.3,isort==5.10.1,jsonschema==4.4.0,lazy-object-proxy==1.7.1,mccabe==0.6.1,packaging==21.3,pbr==5.8.0,pep8-naming==0.11.1,platformdirs==2.4.1,pycodestyle==2.7.0,pycparser==2.21,pydocstyle==6.1.1,pyflakes==2.3.1,pygit2==1.7.2,PyGithub==1.55,Pygments==2.11.2,PyJWT==2.3.0,pylint==2.12.2,PyNaCl==1.5.0,pyparsing==3.0.7,pyrsistent==0.18.1,python-gitlab==3.1.1,PyYAML==6.0,requests==2.27.1,requests-toolbelt==0.9.1,restructuredtext-lint==1.3.2,semantic-version==2.8.5,six==1.16.0,smmap==5.0.0,snowballstemmer==2.2.0,stevedore==3.5.0,testfixtures==6.18.3,toml==0.10.2,typing-extensions==4.0.1,urllib3==1.26.8,webencodings==0.5.1,wemake-python-styleguide==0.16.0,wrapt==1.13.3
pep8 run-test-pre: PYTHONHASHSEED='1079373565'
pep8 run-test: commands[0] | flake8
./gitlabracadabra/packages/destination.py
157:1 DAR202 Excess "Returns" in Docstring: + return
"""Get files key, to upload to. If None, uploaded as body.
Args:
package_file: Source package file.
Returns:
The files key, or None.
"""
^
Full list of violations and explanations:
https://wemake-python-stylegui.de/en/0.16.0/pages/usage/violations/
ERROR: InvocationError for command /home/mathieu/git/gitlab.com/gitlabracadabra/gitlabracadabra/.tox/pep8/bin/flake8 (exited with code 1)
______________________________________________________________________ summary ______________________________________________________________________
ERROR: pep8: commands failed NB: Using tox.ini. |
@sathieu try adding |
@sobolevn This removes the warnings, but only because it's less strict (see https://github.com/terrencepreilly/darglint#strictness-configuration). Also, my intention is I'll keep the noqa for now, without it I would get: def files_key(self, package_file: PackageFile) -> Optional[str]:
"""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 $ tox
[...]
./gitlabracadabra/packages/destination.py
151:5 WPS324 Found inconsistent `return` statement
def files_key(self, package_file: PackageFile) -> Optional[str]:
^
160:9 WPS324 Found inconsistent `return` statement
return None
^ |
This has been closed, but it is not solved. The "solution" proposed is less clear than the proposal by @sathieu. |
What's wrong
How should I write the following code without noqa?
This function is overriden in child classes.
I tried using
return
(withoutNone
). But mypy fails with:I tried without the return line:
See https://gitlab.com/gitlabracadabra/gitlabracadabra/-/merge_requests/233
How it should be
A way to write this code with both flake8 and mypy being happy, and without noqa
Flake8 version and plugins
pip information
python3-pip 20.3.4-4 (Debian package)
OS information
Debian 11 (bullseye)
The text was updated successfully, but these errors were encountered: