-
Notifications
You must be signed in to change notification settings - Fork 0
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
Sourcery refactored main branch #1
base: main
Are you sure you want to change the base?
Conversation
if HAS_ORJSON: | ||
kw["default"] = _orjson_default | ||
return _json.dumps(obj, *args, **kw).decode("utf-8") | ||
else: | ||
if not HAS_ORJSON: | ||
return _json.dumps(obj, *args, **kw) # type: ignore[return-value] | ||
kw["default"] = _orjson_default | ||
return _json.dumps(obj, *args, **kw).decode("utf-8") |
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.
Function dumps
refactored with the following changes:
- Swap if/else branches (
swap-if-else-branches
) - Remove unnecessary else after guard condition (
remove-unnecessary-else
)
# Handle that orjson doesn't support subclasses of str | ||
if isinstance(obj, str): | ||
return str(obj) | ||
else: | ||
encoder = _get_encoder(obj) | ||
return encoder(obj) | ||
encoder = _get_encoder(obj) | ||
return encoder(obj) |
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.
Function _orjson_default
refactored with the following changes:
- Remove unnecessary else after guard condition (
remove-unnecessary-else
)
This removes the following comments ( why? ):
# Handle that orjson doesn't support subclasses of str
else: # We have exited the for loop without finding a suitable encoder | ||
raise TypeError( | ||
f"Object of type '{obj.__class__.__name__}' is not JSON serializable" | ||
) | ||
raise TypeError( | ||
f"Object of type '{obj.__class__.__name__}' is not JSON serializable" | ||
) |
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.
Function _get_encoder
refactored with the following changes:
- If else clause is always executed move code to same level as loop (
useless-else-on-loop
)
This removes the following comments ( why? ):
# We have exited the for loop without finding a suitable encoder
else: | ||
try: | ||
return json.loads(resp.text) | ||
except Exception: | ||
raise NetsuiteAPIResponseParsingError(resp.status_code, resp.text) | ||
try: | ||
return json.loads(resp.text) | ||
except Exception: | ||
raise NetsuiteAPIResponseParsingError(resp.status_code, resp.text) |
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.
Function RestApiBase._request
refactored with the following changes:
- Remove unnecessary else after guard condition (
remove-unnecessary-else
)
if subparser_name == "rest-api": | ||
rest_api_parser.print_help() | ||
return | ||
elif subparser_name == "soap-api": | ||
if subparser_name in ["rest-api", "soap-api"]: |
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.
Function main
refactored with the following changes:
- Simplify conditional into switch-like form (
switch
)
elif existing := out.get(k): | ||
if isinstance(existing, list): | ||
existing.append(v) | ||
else: | ||
out[k] = v | ||
out[k] = [existing, v] | ||
else: | ||
out[k] = v |
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.
Function _parse_headers_arg
refactored with the following changes:
- Merge else clause's nested if statement into elif (
merge-else-if-into-elif
) - Use named expression to simplify assignment and conditional (
use-named-expression
)
if internalIds is None: | ||
internalIds = [] | ||
else: | ||
internalIds = list(internalIds) | ||
if externalIds is None: | ||
externalIds = [] | ||
else: | ||
externalIds = list(externalIds) | ||
|
||
internalIds = [] if internalIds is None else list(internalIds) | ||
externalIds = [] if externalIds is None else list(externalIds) |
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.
Function NetSuiteSoapApi.getList
refactored with the following changes:
- Replace if statement with if expression [×2] (
assign-if-exp
)
if internalIds is None: | ||
internalIds = [] | ||
else: | ||
internalIds = list(internalIds) | ||
if externalIds is None: | ||
externalIds = [] | ||
else: | ||
externalIds = list(externalIds) | ||
|
||
internalIds = [] if internalIds is None else list(internalIds) | ||
externalIds = [] if externalIds is None else list(externalIds) |
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.
Function NetSuiteSoapApi.getItemAvailability
refactored with the following changes:
- Replace if statement with if expression [×2] (
assign-if-exp
)
return "".join([str(random.randint(0, 9)) for i in range(length)]) | ||
return "".join([str(random.randint(0, 9)) for _ in range(length)]) |
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.
Function TokenPassport._generate_nonce
refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore
)
Sourcery Code Quality Report✅ Merging this PR will increase code quality in the affected files by 0.86%.
Here are some functions in these files that still need a tune-up:
Legend and ExplanationThe emojis denote the absolute quality of the code:
The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request. Please see our documentation here for details on how these metrics are calculated. We are actively working on this report - lots more documentation and extra metrics to come! Help us improve this quality report! |
Branch
main
refactored by Sourcery.If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.
See our documentation here.
Run Sourcery locally
Reduce the feedback loop during development by using the Sourcery editor plugin:
Review changes via command line
To manually merge these changes, make sure you're on the
main
branch, then run:Help us improve this pull request!