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

Merged
merged 1 commit into from
Jul 8, 2023
Merged

Sourcery refactored main branch #1

merged 1 commit into from
Jul 8, 2023

Conversation

sourcery-ai[bot]
Copy link

@sourcery-ai sourcery-ai bot commented Jul 8, 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 HaoZeke July 8, 2023 12:15
if hasattr(file, "isatty"):
return file.isatty()
return False
return file.isatty() if hasattr(file, "isatty") else False
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function isatty refactored with the following changes:

Comment on lines -136 to -141
try:
with contextlib.suppress(UnicodeError):
fileobj.write(s)
return
except UnicodeError:
pass

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _write_with_fallback refactored with the following changes:

Comment on lines -195 to +200
if i + 1 == len(args):
color = ""
else:
color = args[i + 1]

color = "" if i + 1 == len(args) else args[i + 1]
if color:
msg = _color_text(msg, color)
_write_with_fallback(msg, file)

_write_with_fallback(end, file)
else:
for i in range(0, len(args), 2):
msg = args[i]
_write_with_fallback(msg, file)
_write_with_fallback(end, file)

_write_with_fallback(end, file)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function color_print refactored with the following changes:

Comment on lines -241 to +232
if x.strip() == "":
return default
return x
return default if x.strip() == "" else x
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_answer_default refactored with the following changes:

Comment on lines -247 to +236
if len(s) > l:
return "..." + s[-(l - 3) :]
else:
return s
return f"...{s[-(l - 3):]}" if len(s) > l else s
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function truncate_left refactored with the following changes:

Comment on lines -165 to +163
else:
str_err = human_float(err / units[i][1], 1, truncate_small=2)
return f"{str_time:s}±{str_err:s}{units[i][0]}"
str_err = human_float(err / units[i][1], 1, truncate_small=2)
return f"{str_time:s}±{str_err:s}{units[i][0]}"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function human_time refactored with the following changes:

@@ -32,6 +32,7 @@
adding a new submodule with an "export_as_benchmark" attribute.
"""


Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 50-51 refactored with the following changes:

Comment on lines -34 to +45
if ignore_case:
attrs = [
getattr(source, key) for key in dir(source) if key.lower() == name.lower()
]

if len(attrs) > 1:
raise ValueError(f"{source.__name__} contains multiple {name} functions.")
elif len(attrs) == 1:
return attrs[0]
else:
return None
else:
if not ignore_case:
return getattr(source, name, None)
attrs = [
getattr(source, key) for key in dir(source) if key.lower() == name.lower()
]

if len(attrs) > 1:
raise ValueError(f"{source.__name__} contains multiple {name} functions.")
elif len(attrs) == 1:
return attrs[0]
else:
return None
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_attr refactored with the following changes:

Comment on lines -276 to +281
if info.defaults is not None:
min_args = max_args - len(info.defaults)
else:
min_args = max_args

min_args = max_args if info.defaults is None else max_args - len(info.defaults)
if info.varargs is not None:
max_args = math.inf

ok = (min_args <= max_num_args) and (min_num_args <= max_args)
if not ok:
if min_args == max_args:
args_str = min_args
else:
args_str = f"{min_args}-{max_args}"
args_str = min_args if min_args == max_args else f"{min_args}-{max_args}"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function check_num_args refactored with the following changes:

Comment on lines -335 to +334
match = address_regex.match(result)
if match:
suspected_address = match.group(2)
if match := address_regex.match(result):
suspected_address = match[2]
# Double check this is the actual address
default_result = object.__repr__(obj)
match2 = address_regex.match(default_result)
if match2:
known_address = match2.group(2)
if match2 := address_regex.match(default_result):
known_address = match2[2]
if known_address == suspected_address:
result = match.group(1) + match.group(3)
result = match[1] + match[3]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _repr_no_address refactored with the following changes:

Comment on lines -467 to +457
self._params = [[item for item in entry] for entry in self._params]
self._params = [list(entry) for entry in self._params]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Benchmark.__init__ refactored with the following changes:

Comment on lines -564 to +573
root, self.name + ": setup_cache", self._setup_cache, 0
root, f"{self.name}: setup_cache", self._setup_cache, 0
)
max_num_args += 1

for setup in self._setups:
ok = ok and check_num_args(
root, self.name + ": setup", setup, min_num_args, max_num_args
root, f"{self.name}: setup", setup, min_num_args, max_num_args
)

ok = ok and check_num_args(
root, self.name + ": call", self.func, min_num_args, max_num_args
root, f"{self.name}: call", self.func, min_num_args, max_num_args
)

for teardown in self._teardowns:
ok = ok and check_num_args(
root, self.name + ": teardown", teardown, min_num_args, max_num_args
root,
f"{self.name}: teardown",
teardown,
min_num_args,
max_num_args,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Benchmark.check refactored with the following changes:

Copy link
Owner

@HaoZeke HaoZeke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually looks quite good.

@HaoZeke HaoZeke merged commit f6a2e9b into main Jul 8, 2023
@HaoZeke HaoZeke deleted the sourcery/main branch July 8, 2023 13:39
HaoZeke added a commit that referenced this pull request Jul 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant