-
Notifications
You must be signed in to change notification settings - Fork 12
Linter: enable attribute-defined-outside-init rule #528
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
base: main
Are you sure you want to change the base?
Changes from 15 commits
d6fe487
ff068d9
0e9e975
bae79cb
bd9a33f
141e479
9913bc8
48b2bfd
0c2e7fb
7020ed2
9b94bb6
38e3945
95a11ee
3167477
64fc8bc
47e26bd
87365b7
e297833
33539b7
9930ecc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -50,7 +50,7 @@ def __init__(self, context_obj=None, body=None, req=None, source=None): | |
| self.parsed_userinput = {} | ||
| self.xml = {} | ||
| self.outgoing_req_redirects = [] | ||
| self.set_body(body) | ||
| self.body = Context.parse_body_object(body) | ||
| self.headers: Headers = Headers() | ||
| self.cookies = {} | ||
| self.query = {} | ||
|
|
@@ -107,26 +107,28 @@ def set_cookies(self, cookies): | |
| self.cookies = cookies | ||
|
|
||
| def set_body(self, body): | ||
| try: | ||
| self.set_body_internal(body) | ||
| except Exception as e: | ||
| logger.debug("Exception occurred whilst setting body: %s", e) | ||
| self.body = Context.parse_body_object(body) | ||
|
|
||
| def set_body_internal(self, body): | ||
| @staticmethod | ||
| def parse_body_object(body): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Method docstring restates what parse_body_object does; explain why these parsing rules exist (e.g., server quirks, expected input shapes) instead of repeating the mechanics. Detailsβ¨ AI Reasoning π§ How do I fix it? More info - Comment |
||
| """Sets the body and checks if it's possibly JSON""" | ||
bitterpanda63 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| self.body = body | ||
| if isinstance(self.body, (str, bytes)) and len(body) == 0: | ||
| # Make sure that empty bodies like b"" don't get sent. | ||
| self.body = None | ||
| if isinstance(self.body, bytes): | ||
| self.body = self.body.decode("utf-8") # Decode byte input to string. | ||
| if not isinstance(self.body, str): | ||
| return | ||
| if self.body.strip()[0] in ["{", "[", '"']: | ||
| # Might be JSON, but might not have been parsed correctly by server because of wrong headers | ||
| parsed_body = json.loads(self.body) | ||
| if parsed_body: | ||
| self.body = parsed_body | ||
| try: | ||
| if isinstance(body, (str, bytes)) and len(body) == 0: | ||
| # Make sure that empty bodies like b"" don't get sent. | ||
| return None | ||
| if isinstance(body, bytes): | ||
| body = body.decode("utf-8") # Decode byte input to string. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. parse_body_object reassigns parameter 'body' (e.g., body = body.decode(...)). Assign decode result to a new local variable to preserve the original argument. Detailsβ¨ AI Reasoning π§ How do I fix it? More info - Comment |
||
| if not isinstance(body, str): | ||
| return body | ||
| if body.strip()[0] in ["{", "[", '"']: | ||
| # Might be JSON, but might not have been parsed correctly by server because of wrong headers | ||
| parsed_body = json.loads(body) | ||
| if parsed_body: | ||
| return parsed_body | ||
| return body | ||
| except Exception as e: | ||
| logger.debug("Exception occurred whilst parsing body: %s", e) | ||
| return body | ||
|
|
||
| def get_route_metadata(self): | ||
| """Returns a route_metadata object""" | ||
|
|
||
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.
This was previously true fyi