-
Notifications
You must be signed in to change notification settings - Fork 796
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
use ruff
as linter
#3008
use ruff
as linter
#3008
Conversation
No explicit `stacklevel` keyword argument found
I cannot assign you as reviewer @binste, but would you be willing to check this? |
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.
Sure! Always happy to review.
Thank you for tackling this and also for going through the rules to see what is available! I'm amazed by the speed of ruff and how many rules are already implemented... Maybe we can even use it as a replacement for black at one point: astral-sh/ruff#1904
Looks mostly good to me. Added some smaller code suggestions. Could you also replace the mention of flake8 in contributing.md?
altair/utils/schemapi.py
Outdated
@@ -564,11 +564,17 @@ def to_dict(self, validate=True, ignore=None, context=None): | |||
try: | |||
self.validate(result) | |||
except jsonschema.ValidationError as err: | |||
raise SchemaValidationError(self, err) | |||
raise SchemaValidationError(self, err) from err |
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.
raise SchemaValidationError(self, err) from err | |
# We do not raise `from err` as else the resulting | |
# traceback is very long as it contains part | |
# of the Vega-Lite schema. It would also first | |
# show the less helpful ValidationError instead of | |
# the more user friendly SchemaValidationError | |
raise SchemaValidationError(self, err) from 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.
I've modified your suggestion a little bit to raise from None
instead of raise # noqa: B904
. I'm not entirely sure if that leads to the same behavior. Do you have an example how you checked this?
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.
Double-checked and that works as well. It gives the same traceback as in master which is good. I tested it with:
import altair as alt
from vega_datasets import data
(
alt.Chart(data.barley())
.mark_bar()
.encode(
x=alt.X("variety", unknown=2),
y=alt.Y("sum(yield)", stack="asdf"),
)
)
tools/schemapi/schemapi.py
Outdated
@@ -562,11 +562,17 @@ def to_dict(self, validate=True, ignore=None, context=None): | |||
try: | |||
self.validate(result) | |||
except jsonschema.ValidationError as err: | |||
raise SchemaValidationError(self, err) | |||
raise SchemaValidationError(self, err) from err |
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.
raise SchemaValidationError(self, err) from err | |
# We do not raise `from err` as else the resulting | |
# traceback is very long as it contains part | |
# of the Vega-Lite schema. It would also first | |
# show the less helpful ValidationError instead of | |
# the more user friendly SchemaValidationError | |
raise SchemaValidationError(self, err) from 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.
Same change as above, raise from None
instead of rase # noqa: B904
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.
Thanks for the review @binste. I've one inline question remaining.
Hm, it seems there are some sync issues with VSCode replies. Let me respond using the replies on github website. |
Hm, didn't realize this, but I think we can remove In that case |
I didn't find any options for ruff to enable checks on code formatting. Also tested it on some code where black correctly shows an error but ruff does not. The FAQ state that "As a project, Ruff is designed to be used alongside Black and, as such, will defer implementing stylistic lint rules that are obviated by autoformatting." So I'd assume that the checking comes hand-in-hand with the autoformat capability and we need to wait for that. |
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.
Looks good! This inspired me to start using ruff at work as well.
Thanks @binste! Great that the insights here is more useful than this PR alone👍. |
Sorry for the drive-by comment but I just saw this is in Ruff's dependency graph and as a long-time Altair user I can't help but mention how cool it is to be able to support the project. Let me know if you ever run into issues with Ruff or have questions on usage etc. |
That's great, thank you for taking the time to comment and offering your support @charliermarsh ! |
This PR add ruff as linter over flake8. This in order to work towards a complete pyproject.toml-based build, see corresponding PR #3007.
I've moved the flake8 configuration to the corresponding ruff section in the pyproject.toml file. I tried to synchronize the same tests for now. But still had to apply some fixes in the code to get in sync
pycodestyle
rules astral-sh/ruff#2402, so these cannot be excluded yet (as they were for flake8).Ready for review.