[flake8-bugbear
] Do not raise error if keyword argument is present and target-python version is less or equals than 3.9 (B903
)
#15549
+118
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
[
flake8-bugbear
] Do not raise error if keyword argument is present and target-python version is less or equals than 3.9 (B903
)Summary
I have this piece of code in one of my repo
When I did this, I started by using dataclass, although I wanted the 3 arguments of the init function to be keywords only. As dataclass does not support kw_only before python 3.10 (reference https://docs.python.org/3/library/dataclasses.html#module-contents), I ended up writing the init function myself.
With the current implementation of B903, this will raise an error. My suggestion would be not to raise error if an keyword only argument and target-version<=3.9.
Related github issue : #15548
Test Plan
I added a new usecase in
class_as_data_structure.py
, a class with keyword only.I tested this file with the target-version = latest python and with python3.9.
With the latest python, I'm expecting error and python3.9 no error should be raised.