-
Notifications
You must be signed in to change notification settings - Fork 2
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
Add an option to force future annotations imports on all files #5
Conversation
Codecov Report
@@ Coverage Diff @@
## main #5 +/- ##
===========================================
- Coverage 100.00% 96.55% -3.45%
===========================================
Files 1 1
Lines 46 58 +12
===========================================
+ Hits 46 56 +10
- Misses 0 2 +2
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## main #5 +/- ##
===========================================
- Coverage 100.00% 96.55% -3.45%
===========================================
Files 1 1
Lines 46 58 +12
===========================================
+ Hits 46 56 +10
- Misses 0 2 +2
Continue to review full report at Codecov.
|
@@ -78,6 +79,7 @@ def visit_Attribute(self, node: ast.Attribute) -> None: | |||
class FutureAnnotationsChecker: | |||
name = "flake8-future-annotations" | |||
version = "0.0.4" | |||
force_future_annotations = False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why make this a class-level attribute? Seems like we could just define this variable in __init__
instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that parse_options
must be a classmethod
else it does not work with flake8. This is why I put the attribute on the class itself and not the instance.
Tell me if I'm missing something.
tests/test_checker.py
Outdated
|
||
assert len(errors) == 0, (str(filepath), errors) | ||
|
||
@pytest.mark.parametrize("force_future_annotations", (False, True)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add separate test cases for this feature? I don't think we need to touch the existing test cases.
Having all test cases combined into a mega test makes it difficult to read.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tell me if that's better now
flake8_future_annotations/checker.py
Outdated
"--force-future-annotations", | ||
action="store_true", | ||
parse_from_config=True, | ||
help="Force the use of future annotations imports", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
help="Force the use of from __future__ import annotations in all files.",
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
flake8_future_annotations/checker.py
Outdated
yield lineno, char_offset, message, type(self) | ||
|
||
@staticmethod | ||
def add_options(option_manager: Any) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use OptionManager
instead of Any
?
from flake8.options.manager import OptionManager
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried but mypy complains that there are no types exposed for flake8 module.
I found this issue on the flake8 repo which seems relevant.
If you prefer I can use OptionManager
anyways and telling mypy to ignore it (making it typechecked as if it was Any
).
Thanks for the contribution! I left some comments of things to fix, but overall it looks like a good change. |
I'm having trouble testing this via
This error is blocking the merge + release of this PR. If you can help me debug this (I suspect it might be a local issue?), that would help me a lot |
Hello @TylerYep and sorry for the issue, I had an old virtualenv which was preventing me from catching it. After some non-trivial debugging, I added a commit to this PR to fix the problem. It seems that Note that you may need to delete your virtualenv and create a new one from scratch (in which you run Tell me if that works for you! |
Thank you for fixing the error! I have tested+merged the change and will put out a new release within the next few days. |
Fantastic! Thank you 🥳 |
Hello,
This PR adds an optional flag
--force-future-annotations
(or config parameter).If provided, the plugin also reports files missing the
from __future__ import annotations
import even if PEP 563 would not have allowed to rewrite anything. In that case, code FA101 is used instead of FA100.This allows to make sure that all linted files include the future import, which one may want for consistency.
Of course, feel free to suggest any changes 🙂