-
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
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.
Due to GitHub API limits, only the first 60 comments can be shown.
# Make sure to sync the versions of common dependencies (absl-py, numpy, | ||
# six, and protobuf) with TF. |
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.
Lines 178-217
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
)
This removes the following comments ( why? ):
# Make sure to sync the versions of common dependencies (absl-py, numpy,
# six, and protobuf) with TF.
raise ValueError("Could not guess file format for: {}".format(filename)) | ||
raise ValueError(f"Could not guess file format for: {filename}") |
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 guess_file_format
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
)
return match.group(1) if match else file_pattern | ||
return match[1] if match else file_pattern |
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_base_filename
refactored with the following changes:
- Replace m.group(x) with m[x] for re.Match objects (
use-getitem-for-re-match-groups
)
match = re.fullmatch(r"(.*)@(\d+)", file_pattern) | ||
if not match: | ||
if match := re.fullmatch(r"(.*)@(\d+)", file_pattern): | ||
return "{}-?????-of-{:05d}".format(match[1], int(match[2])) | ||
else: | ||
return file_pattern | ||
num_shards = int(match.group(2)) | ||
return "{}-?????-of-{:05d}".format(match.group(1), num_shards) |
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 expand_sharded_pattern
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
) - Lift code into else after jump in control flow (
reintroduce-else
) - Swap if/else branches (
swap-if-else-branches
) - Inline variable that is only used once (
inline-variable
) - Replace m.group(x) with m[x] for re.Match objects [×2] (
use-getitem-for-re-match-groups
)
# TODO(blais): Eventually support file suffixes. | ||
match = re.fullmatch(r"(.*)@(\d+)", pattern) | ||
if match: | ||
if match := re.fullmatch(r"(.*)@(\d+)", pattern): | ||
# Beam would unpack automatically for internal containers, but we need this | ||
# for the open source implementation of the Beam runner. | ||
return dict(file_path_prefix=match.group(1), | ||
num_shards=int(match.group(2)), | ||
shard_name_template="-SSSSS-of-NNNNN") | ||
return dict( | ||
file_path_prefix=match[1], | ||
num_shards=int(match[2]), | ||
shard_name_template="-SSSSS-of-NNNNN", | ||
) | ||
if match := re.fullmatch(r"(.*)-(?:\d|\?){5}-of-(\d{5})", pattern): | ||
return dict( | ||
file_path_prefix=match[1], | ||
num_shards=int(match[2]), | ||
shard_name_template="-SSSSS-of-NNNNN", | ||
) | ||
else: | ||
match = re.fullmatch(r"(.*)-(?:\d|\?){5}-of-(\d{5})", pattern) | ||
if match: | ||
return dict(file_path_prefix=match.group(1), | ||
num_shards=int(match.group(2)), | ||
shard_name_template="-SSSSS-of-NNNNN") | ||
else: | ||
return dict(file_path_prefix=pattern, | ||
num_shards=None, shard_name_template="") | ||
return dict(file_path_prefix=pattern, | ||
num_shards=None, shard_name_template="") |
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_sharded_pattern_args
refactored with the following changes:
- Use named expression to simplify assignment and conditional [×2] (
use-named-expression
) - Replace m.group(x) with m[x] for re.Match objects [×4] (
use-getitem-for-re-match-groups
) - Remove unnecessary else after guard condition (
remove-unnecessary-else
)
This removes the following comments ( why? ):
# TODO(blais): Eventually support file suffixes.
node_sets_spec = _ifnone(node_sets_spec, dict()) | ||
edge_sets_spec = _ifnone(edge_sets_spec, dict()) | ||
node_sets_spec = _ifnone(node_sets_spec, {}) | ||
edge_sets_spec = _ifnone(edge_sets_spec, {}) |
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 GraphTensorSpec.from_piece_specs
refactored with the following changes:
- Replace
dict()
with{}
[×2] (dict-literal
)
if node_sets: | ||
return first_by_name(node_sets) | ||
return context | ||
return first_by_name(node_sets) if node_sets else context |
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_indicative_graph_entity
refactored with the following changes:
- Lift code into else after jump in control flow (
reintroduce-else
) - Replace if statement with if expression (
assign-if-exp
)
if isinstance(data, Mapping): | ||
self._data = data | ||
else: | ||
self._data = dict(data) | ||
self._data = data if isinstance(data, Mapping) else dict(data) |
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 _ImmutableMapping.__init__
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
)
result.update( | ||
_flatten_graph_field_specs(graph_spec.context_spec, | ||
f'{prefix}{gc.CONTEXT}/')) | ||
result |= _flatten_graph_field_specs(graph_spec.context_spec, | ||
f'{prefix}{gc.CONTEXT}/') |
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 _
refactored with the following changes:
- Merge dictionary updates via the union operator (
dict-assign-update-to-union
)
result.update(_prefix_keys(node_set_spec.features_spec, prefix)) | ||
result |= _prefix_keys(node_set_spec.features_spec, prefix) |
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 _
refactored with the following changes:
- Merge dictionary updates via the union operator (
dict-assign-update-to-union
)
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
This is work-in-progress PiperOrigin-RevId: 491067724
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!