-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
[BEAM-11516] Upgrade to pylint 2.11.1, fix warnings #15612
Conversation
Codecov Report
@@ Coverage Diff @@
## master #15612 +/- ##
==========================================
+ Coverage 83.76% 83.80% +0.03%
==========================================
Files 444 444
Lines 60418 60462 +44
==========================================
+ Hits 50612 50668 +56
+ Misses 9806 9794 -12
Continue to review full report at Codecov.
|
Run Python 3.7 PostCommit |
Hi @TheNeuralBit, would you help me to review this? |
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.
Thank you this looks great! I looked over ~100 of the 237 files. Just to summarize the code changes for posterity:
- super calls have all changed to
super().__init__
(super-with-arguments) - re-raised errors include
from e
(raise-missing-from) dict()
->{}
(use-dict-literal)- check dictionary membership directly rather than using
x in dict.keys()
(consider-iterating-dictionary) - avoid creating intermediate list when creating a tuple (
tuple([..])
->tuple()
) (not sure what pylint code this is) - Change imports like
import apache_beam.transforms.window as window
tofrom apache_beam.transforms import window
For reference: https://pylint.pycqa.org/en/latest/technical_reference/features.html
These all look like positive changes that shouldn't have any user-visible impact, except for the fixes for raise-missing-from. In many places we already have logic to inform the user about the underlying error, so it's redundant to use the from
syntax as well. In general I think the from
syntax is preferable, but we need to look over the exceptions to dedupe this.
Given the extreme risk of merge conflicts (this PR touches the entire code base), I'd recommend we back out the changes to the exceptions and file a follow-up jira to figure out what to do there (might be worth raising on dev@ too). That way we can go ahead and get the non-controversial changes merged before conflicts arise.
# Re-raise the original exception since we finished the retries. | ||
raise exn.with_traceback(exn_traceback) |
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.
Here it looks intentional to not include stop_iteration
. Could you disable the check instead?
@@ -23,7 +23,7 @@ | |||
# pytype: skip-file | |||
# mypy: check-untyped-defs | |||
|
|||
import cProfile # pylint: disable=bad-python3-import | |||
import cProfile # pylint: disable=bad-option-value |
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.
What is this for?
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.
I removed it
else: | ||
raise RuntimeError("Full trace: {}, \ | ||
output of the failed child process {} "\ | ||
.format(traceback.format_exc(), error.output)) | ||
.format(traceback.format_exc(), error.output)) from error |
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.
Nearly all of the exceptions in this file already include logic to print the original traceback in the error message. That's not necessary now that we have from error
. Could you remove the trackeback.format_exc()
logic?
@@ -747,6 +747,7 @@ def encode_to_stream(self, value, out, nested): | |||
def decode_from_stream(self, in_, nested): | |||
# type: (create_InputStream, bool) -> IntervalWindow | |||
if not TYPE_CHECKING: | |||
# pylint: disable=global-variable-not-assigned |
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.
I think this will disable the check for the entire block, not just the line. You might put at the end of the line or use disable-next
instead (docs)
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.
Changed
@@ -195,7 +195,7 @@ def shuffled(seq): | |||
random.shuffle(seq) | |||
return seq | |||
|
|||
# pylint: disable=range-builtin-not-iterating | |||
# pylint: disable=bad-option-value | |||
part = pd.Series(shuffled(range(len(df))), index=df.index) % num_partitions |
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.
What is ths issue here?
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.
Removed
@@ -279,7 +279,7 @@ def checksum(self, path): | |||
try: | |||
return s3io.S3IO(options=self._options).checksum(path) | |||
except Exception as e: # pylint: disable=broad-except | |||
raise BeamIOError("Checksum operation failed", {path: e}) | |||
raise BeamIOError("Checksum operation failed", {path: e}) from e |
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.
It looks like these exceptions are already doing something with the original exception. Could you verify if we actually need the from e
or not? I'd like to avoid printing the culprit stacktrace twice. (Same goes for other BeamIOErrors you've changed)
@@ -328,6 +328,7 @@ def _delete_path(path): | |||
match_result = self.match([path_to_use])[0] | |||
statuses = gcsio.GcsIO().delete_batch( | |||
[m.path for m in match_result.metadata_list]) | |||
# pylint: disable=used-before-assignment |
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.
Is this a false-positive? I can't see what it's upset about.
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.
I think it is a false-positive
sdks/python/.pylintrc
Outdated
@@ -143,6 +147,7 @@ disable = | |||
unnecessary-pass, | |||
unneeded-not, | |||
unsubscriptable-object, | |||
unspecified-encoding, |
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.
Some of these may be useful to apply eventually. unspecified-encoding
in particular we should probably fix. Since Beam runs on distributed worker environments that may have surprising default encodings, it's good for our code to be explicit about encodings.
We could add a TODO and file a follow-up jira if it's too much to take on in this PR though.
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.
Jira BEAM-12992 created to follow up unspecified-encoding
warning
I created BEAM-12991 to follow up |
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.
Thanks for the quick turnaround! I want to send a message out to dev@ about this, but will try to merge today.
Thank you @TheNeuralBit! |
* [BEAM-11516] Upgrade pylint 2.11.1, fix warnings * [BEAM-11516] Fix typo * [BEAM-11516] Fix error infering __class__ * [BEAM-11516] Rollback operations super style * [BEAM-11516] Fix style * [BEAM-11516] Rollback raise-missing-from fixed warnings * [BEAM-11516] Remove unused pylint disable comments, add TODOs to enable some warnings * [BEAM-11516] Remove from error leftover * [BEAM-11516] Fix pylint warnings
Please add a meaningful description for your change here
Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:
R: @username
).[BEAM-XXX] Fixes bug in ApproximateQuantiles
, where you replaceBEAM-XXX
with the appropriate JIRA issue, if applicable. This will automatically link the pull request to the issue.CHANGES.md
with noteworthy changes.See the Contributor Guide for more tips on how to make review process smoother.
ValidatesRunner
compliance status (on master branch)Examples testing status on various runners
Post-Commit SDK/Transform Integration Tests Status (on master branch)
Pre-Commit Tests Status (on master branch)
See .test-infra/jenkins/README for trigger phrase, status and link of all Jenkins jobs.
GitHub Actions Tests Status (on master branch)
See CI.md for more information about GitHub Actions CI.