-
Notifications
You must be signed in to change notification settings - Fork 687
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
ruff prep #5764
ruff prep #5764
Conversation
Signed-off-by: Flynn <[email protected]>
Signed-off-by: Flynn <[email protected]>
Signed-off-by: Flynn <[email protected]>
Signed-off-by: Flynn <[email protected]>
Signed-off-by: Flynn <[email protected]>
Signed-off-by: Flynn <[email protected]>
Signed-off-by: Flynn <[email protected]>
Signed-off-by: Flynn <[email protected]>
Signed-off-by: Flynn <[email protected]>
60bf309
to
d7858b5
Compare
@@ -241,7 +241,7 @@ def good_ambassador_id(self, resource: dict): | |||
# Make sure it's a list. Yes, this is Draconian, | |||
# but the jsonschema will allow only a string or a list, | |||
# and guess what? Strings are Iterables. | |||
if type(allowed_ids) != list: | |||
if type(allowed_ids) is not list: |
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.
if type(allowed_ids) is not list: | |
if not isinstance(allowed_ids, list): |
@@ -31,6 +31,10 @@ class _CompileResult(TypedDict): | |||
xds: NotRequired[EnvoyConfig] | |||
|
|||
|
|||
def null_file_checker(path: str) -> bool: |
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.
def null_file_checker(path: str) -> bool: | |
def null_file_checker(_: str) -> bool: |
Tiny nit - unused variables shouldn't be bound to names
@@ -430,7 +430,7 @@ def process(self, resource: ACResource) -> RichStatus: | |||
|
|||
try: | |||
handler(resource) | |||
except Exception as e: | |||
except Exception: |
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.
If nothing is being done here, why is the exception being caught? Usually, you'd expect something like:
try:
handler(resource)
except Exception as error:
raise SomeCustomError from error
So that the traceback and context are preserved.
Haven't had time to dive into the full context here so it's a genuine question, not a criticism or anything 😅
@@ -24,7 +24,7 @@ def __init__(self, config: "V3Config") -> None: | |||
|
|||
self.update( | |||
{ | |||
"listeners": [l.as_dict() for l in config.listeners], | |||
"listeners": [x.as_dict() for x in config.listeners], |
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.
"listeners": [x.as_dict() for x in config.listeners], | |
"listeners": [listener.as_dict() for listener in config.listeners], |
Absolutely a tiny nit, please feel 100% free to ignore it, just a personal preference for short-but-descriptive variable names over generic or shortest-possible ones.
@@ -406,13 +406,13 @@ def __init__( | |||
|
|||
request_headers_to_remove = group.get("remove_request_headers", None) | |||
if request_headers_to_remove: | |||
if type(request_headers_to_remove) != list: | |||
if type(request_headers_to_remove) is not list: |
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.
if type(request_headers_to_remove) is not list: | |
if not isinstance(request_headers_to_remove, list): |
request_headers_to_remove = [request_headers_to_remove] | ||
self["request_headers_to_remove"] = request_headers_to_remove | ||
|
||
response_headers_to_remove = group.get("remove_response_headers", None) | ||
if response_headers_to_remove: | ||
if type(response_headers_to_remove) != list: | ||
if type(response_headers_to_remove) is not list: |
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.
if type(response_headers_to_remove) is not list: | |
if not isinstance(response_headers_to_remove, list): |
@@ -68,7 +68,7 @@ def _cors_normalize(value: Any) -> Any: | |||
are returned unaltered. | |||
""" | |||
|
|||
if type(value) == list: | |||
if type(value) is list: |
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.
if type(value) is list: | |
if isinstance(value, list): |
I've been messing with uv and ruff (thanks, @the-wondersmith!) and wow, they are fast enough to legit be game-changers. This PR cleans up the Python code in line with what ruff wants.
Reviewers: going commit by commit will probably be simpler but it's not that big a deal.