Skip to content

STYLE enable pylint: confusing-with-statement #49789

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

Merged

Conversation

natmokval
Copy link
Contributor

@natmokval natmokval commented Nov 19, 2022

Issue #48855. This PR enables pylint type "W" warning: confusing-with-statement

After fixing the warning confusing-with-statement running pandas/tests/io/test_pickle.py raises an error EOFError: Ran out of input. To handle this error I check if the size of the file is not zero. Maybe there is a better way to deal with the test?

Comment on lines 286 to 287
with open(src_path, "rb") as fh, f:
with open(src_path, "rb") as fh:
f.write(fh.read())
Copy link
Member

Choose a reason for hiding this comment

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

does it work to nest the with statements? like

with open(src_path, 'rb') as fh:
    with f:
        f.write(fh.read())

?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, @MarcoGorelli, it works like a charm. I updated the commit.

@MarcoGorelli MarcoGorelli added the Code Style Code style, linting, code_checks label Nov 19, 2022
@MarcoGorelli MarcoGorelli added this to the 2.0 milestone Nov 19, 2022
Copy link
Member

@MarcoGorelli MarcoGorelli left a comment

Choose a reason for hiding this comment

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

thanks @natmokval !

@@ -352,7 +353,6 @@ def test_read_explicit(self, compression, get_random_path):

# read compressed file
df2 = pd.read_pickle(p2, compression=compression)

Copy link
Member

Choose a reason for hiding this comment

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

for the future, it's better to not delete unrelated lines, but it's fine here

@MarcoGorelli MarcoGorelli merged commit e660f2c into pandas-dev:main Nov 19, 2022
mliu08 pushed a commit to mliu08/pandas that referenced this pull request Nov 27, 2022
* STYLE enable pylint: confusing-with-statement

* STYLE enable pylint: confusing-with-statement II
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Code Style Code style, linting, code_checks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants