Skip to content
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

Closed
sathieu opened this issue Jan 7, 2022 · 5 comments
Closed

Allow to return None without noqa #2323

sathieu opened this issue Jan 7, 2022 · 5 comments
Labels
bug Something isn't working dependencies Pull requests that update a dependency file

Comments

@sathieu
Copy link
Contributor

sathieu commented Jan 7, 2022

What's wrong

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.

I tried using return (without None). But mypy fails with:

mypy run-test: commands[0] | mypy gitlabracadabra
gitlabracadabra/packages/destination.py:160: error: Return value expected

I tried without the return line:

  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.
        """

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

installed: astor==0.8.1,astroid==2.9.2,attrs==21.4.0,bandit==1.7.1,certifi==2021.10.8,cffi==1.15.0,charset-normalizer==2.0.10,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:///builds/gitlabracadabra/gitlabracadabra/.tox/.tmp/package/1/gitlabracadabra-1.4.0a0.zip,GitPython==3.1.25,html5lib==1.1,idna==3.3,isort==5.10.1,jsonschema==4.3.3,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.4.0,pyparsing==3.0.6,pyrsistent==0.18.0,python-gitlab==3.0.0,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.7,webencodings==0.5.1,wemake-python-styleguide==0.16.0,wrapt==1.13.3

pip information

python3-pip 20.3.4-4 (Debian package)

OS information

Debian 11 (bullseye)

@sathieu sathieu added the bug Something isn't working label Jan 7, 2022
@sobolevn sobolevn added the dependencies Pull requests that update a dependency file label Jan 7, 2022
@sobolevn
Copy link
Member

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:

  1. flake8 ex.py --isolated --strictness=long --docstring-style=numpy passes
  2. mypy ex.py also passes with the config we have in this repo

I am going to close this as non-repro. Please, feel free to reopen if you have a working reporduction 🙂

@sathieu
Copy link
Contributor Author

sathieu commented Jan 31, 2022

@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.

@sobolevn
Copy link
Member

@sathieu try adding --strictness=long --docstring-style=numpy 🙂

@sathieu
Copy link
Contributor Author

sathieu commented Jan 31, 2022

@sobolevn This removes the warnings, but only because it's less strict (see https://github.com/terrencepreilly/darglint#strictness-configuration).

Also, my intention is return None (and not return or no return at all), the description of the method says If None, uploaded as body.

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
  ^

@vnmabus
Copy link

vnmabus commented Nov 10, 2023

This has been closed, but it is not solved. The "solution" proposed is less clear than the proposal by @sathieu.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working dependencies Pull requests that update a dependency file
Projects
None yet
Development

No branches or pull requests

3 participants