Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

sourcery-ai[bot]
Copy link

@sourcery-ai sourcery-ai bot commented Mar 10, 2023

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:

git fetch origin sourcery/main
git merge --ff-only FETCH_HEAD
git reset HEAD^

Help us improve this pull request!

@sourcery-ai sourcery-ai bot requested a review from Alaricniall March 10, 2023 09:22
Comment on lines -24 to +27
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")
Copy link
Author

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:

Comment on lines -34 to +36
# 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)
Copy link
Author

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:

This removes the following comments ( why? ):

# Handle that orjson doesn't support subclasses of str

Comment on lines -53 to +52
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"
)
Copy link
Author

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:

This removes the following comments ( why? ):

# We have exited the for loop without finding a suitable encoder

Comment on lines -49 to +52
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)
Copy link
Author

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:

if subparser_name == "rest-api":
rest_api_parser.print_help()
return
elif subparser_name == "soap-api":
if subparser_name in ["rest-api", "soap-api"]:
Copy link
Author

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)

Comment on lines +360 to +366
elif existing := out.get(k):
if isinstance(existing, list):
existing.append(v)
else:
out[k] = v
out[k] = [existing, v]
else:
out[k] = v
Copy link
Author

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:

Comment on lines -360 to +361
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)
Copy link
Author

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:

Comment on lines -485 to +479
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)
Copy link
Author

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:

return "".join([str(random.randint(0, 9)) for i in range(length)])
return "".join([str(random.randint(0, 9)) for _ in range(length)])
Copy link
Author

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:

@sourcery-ai
Copy link
Author

sourcery-ai bot commented Mar 10, 2023

Sourcery Code Quality Report

✅  Merging this PR will increase code quality in the affected files by 0.86%.

Quality metrics Before After Change
Complexity 2.65 ⭐ 2.19 ⭐ -0.46 👍
Method Length 38.93 ⭐ 38.80 ⭐ -0.13 👍
Working memory 3.88 ⭐ 3.73 ⭐ -0.15 👍
Quality 79.30% 80.16% 0.86% 👍
Other metrics Before After Change
Lines 1096 1072 -24
Changed files Quality Before Quality After Quality Change
netsuite/json.py 88.96% ⭐ 90.13% ⭐ 1.17% 👍
netsuite/rest_api_base.py 78.33% ⭐ 78.77% ⭐ 0.44% 👍
netsuite/cli/main.py 54.04% 🙂 55.47% 🙂 1.43% 👍
netsuite/cli/rest_api.py 67.73% 🙂 68.23% 🙂 0.50% 👍
netsuite/soap_api/client.py 91.37% ⭐ 92.74% ⭐ 1.37% 👍
netsuite/soap_api/passport.py 87.46% ⭐ 87.60% ⭐ 0.14% 👍

Here are some functions in these files that still need a tune-up:

File Function Complexity Length Working Memory Quality Recommendation
netsuite/cli/rest_api.py _add_rest_api_get_parser 12 🙂 240 ⛔ 41.85% 😞 Try splitting into smaller methods
netsuite/cli/rest_api.py _add_rest_api_openapi_serve_parser 3 ⭐ 246 ⛔ 54.14% 🙂 Try splitting into smaller methods
netsuite/cli/main.py main 6 ⭐ 234 ⛔ 8 🙂 54.48% 🙂 Try splitting into smaller methods
netsuite/rest_api_base.py RestApiBase._request_impl 1 ⭐ 149 😞 10 😞 62.03% 🙂 Try splitting into smaller methods. Extract out complex expressions
netsuite/soap_api/client.py NetSuiteSoapApi.getList 3 ⭐ 115 🙂 10 😞 64.02% 🙂 Extract out complex expressions

Legend and Explanation

The emojis denote the absolute quality of the code:

  • ⭐ excellent
  • 🙂 good
  • 😞 poor
  • ⛔ very poor

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

0 participants