-
Notifications
You must be signed in to change notification settings - Fork 93
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
Lint #6161
Lint #6161
Conversation
4f9c623
to
60d4f77
Compare
@@ -72,7 +72,7 @@ def get_broadcast_change_iter(modified_settings, is_cancel=False): | |||
value = setting | |||
keys_str = "" | |||
while isinstance(value, dict): | |||
key, value = list(value.items())[0] | |||
key, value = next(iter(value.items())) |
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.
RUF015: Get the first item from the iterator rather than working through the whole iterator, turning it into a list, then getting the first item.
@@ -129,7 +129,7 @@ def _clean_check(opts: 'Values', id_: str, run_dir: Path) -> None: | |||
except ContactFileExists as exc: | |||
raise ServiceFileError( | |||
f"Cannot clean running workflow {id_}.\n\n{exc}" | |||
) | |||
) 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.
B904: Don't include the ContactFileExists exception context in the ServiceFileError.
@@ -235,7 +235,7 @@ def _report( | |||
""" | |||
try: | |||
ret: List[Tuple[Optional[str], Optional[str], bool]] = [] | |||
for _mutation_name, mutation_response in response.items(): | |||
for mutation_response in response.values(): |
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.
PERF101: don't needless iterate items
keys.append(api_key) | ||
shuffle(keys) | ||
return keys[0].strip() | ||
return choice(list(api_keys)).strip() # nosec |
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.
PERF402: Don't build an entire list when you only need one item
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.
Nice, worth doing!
Small lint fixes for rules not currently covered by our CI, low priority.
Took
ruff
for a spin to see how handy its code fixers are (it's not just a linter, it can fix some issues for you). Some of the fixers are kinda useful, but most the good rules have to be done manually, so turns out they aren't that helpful for us, worth a try, never mind.Kept a four of the fixes and turned them into this PR. They're mostly small, but B904 created a good bit of diff. Long story short, if you're re-raising an exception with a more helpful class/message, you generally want to do
raise Exception(...) from None
, otherwise the context of the exception you're re-raising is included in the traceback which kinda defates the object.I.E:
Preserves the parent exception context resulting in a confusing traceback:
Whereas:
Chops off the parent context:
Using
from exc
is the same as the default behaviour (just more explicit).Raising the whole exception tree is a useful feature for debugging uncaught errors, but not so good for errors we are trying to niceify for users.
Check List
CONTRIBUTING.md
and added my name as a Code Contributor.setup.cfg
(andconda-environment.yml
if present).CHANGES.md
entry included if this is a change that can affect users?.?.x
branch.