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

B905 is raised on python 3.7 #320

Closed
kasium opened this issue Dec 9, 2022 · 6 comments
Closed

B905 is raised on python 3.7 #320

kasium opened this issue Dec 9, 2022 · 6 comments

Comments

@kasium
Copy link
Contributor

kasium commented Dec 9, 2022

When having a zip call like zip(a,b), the latest bugbear release raises zip() without an explicit strict= parameter.
However, on python 3.7-3.9 this parameter is not present and therefore the check should ignore them

@jakkdl
Copy link
Contributor

jakkdl commented Dec 9, 2022

Unless the check is not excluded by default, which would be a bug, this is working as intended as per #311 (comment)

So the intended solution is not to enable the check for <3.10, as per the README:

B905: zip() without an explicit strict= parameter set. strict=True causes the resulting iterator to raise a ValueError if the arguments are exhausted at differing lengths. The strict= argument was added in Python 3.10, so don't enable this flag for code that should work on <3.10. For more information: https://peps.python.org/pep-0618/

@kasium
Copy link
Contributor Author

kasium commented Dec 9, 2022

@jakkdl but wouldn't it be good if you would check if the current python version supports that flag? So if you run on python 3.7 you get no error and if running on python 3.10 you get it. With that less configuration is needed

@jakkdl
Copy link
Contributor

jakkdl commented Dec 9, 2022

The problem is that there's no easy way of figuring out what versions of python your code is supposed to run on. One could add a check so that the error isn't raised if the version of python that flake8 is running with currently is python3.7, i.e. you run it with python3.7 -m flake8, or you've set up your virtualenv to be with python3.7, but I think the vast majority of codebases that support python3.7 do it in addition to later versions in which case the version of python that flake8 is currently running on can be later than 3.7, but the underlying code is supposed to work with 3.7 as well.

Unfortunately specifying the required python versions of your code can be done in several different files: setup.py, setup.cfg, pyproject.toml, etc - which is why it was decided not to bother trying to parse that.

@kasium
Copy link
Contributor Author

kasium commented Dec 9, 2022

I fully unterstand your comment and the limitations.
What about the following: we should not try to get the python version somewhere from setup.py or so. We should just check if the current python runtime is at least 3.10. In the case a project is compatible with 3.7 but runs flake8 on 3.10, they can still disable the error on demand. What do you think?

@jakkdl
Copy link
Contributor

jakkdl commented Dec 9, 2022

I'm not sure how common that case is, but probably doesn't hurt. Feel free to submit a PR, it should be as simple as

if sys.version_info[:2] < 3.10:
  return  # pragma: no cover

at the start of check_b905.

@cooperlees
Copy link
Collaborator

cooperlees commented Dec 9, 2022

My only worry here is the one edge case and why I didn’t push this in the initial PR is if someone wants to lint >=3.10 code with <3.10 … I don’t think this is a big use case tho like you both …

kasium added a commit to kasium/flake8-bugbear that referenced this issue Dec 12, 2022
@kasium kasium closed this as not planned Won't fix, can't repro, duplicate, stale Dec 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants