Page MenuHomePhabricator

Fix detection of binary open() calls in the Python encoding linter
ClosedPublic

Authored by jasonbcox on Sep 2 2020, 21:14.

Details

Summary

Currently, the python file encoding linter incorrectly identifies some cases of open() needing an encoding explicitly set when they in fact do not.
Reading/writing binary files should not set an encoding, so this false positive lint message will lead the developer to produce incorrect code
if the message is to be believed.

This patch fixes the pattern matching for binary-mode open() calls, which will allow the buildbot code to be ported to this repository
without breaking the linter.

Test Plan
arc lint --everything

Diff Detail

Repository
rABC Bitcoin ABC
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

deadalnix requested changes to this revision.Sep 2 2020, 23:39
deadalnix added a subscriber: deadalnix.

I have no idea what problem this fixes.

Sure, this match different things. Ok. Why should it match these things? What problem happens when it doesn't?

This revision now requires changes to proceed.Sep 2 2020, 23:39

I have no idea what problem this fixes.

Sure, this match different things. Ok. Why should it match these things? What problem happens when it doesn't?

  1. [^,]*, Only matches one comma, so calls to open() where the first arg is composed of other calls (in the above example, it's os.path.join(os.path.dirname(__file__), 'resources', 'teamcity-icon-16.base64')), the match is incorrect.
  2. I misread the [^'\"] and should have removed it. Will fix. The new matching intends to restrict the file mode matching so that it doesn't just match the first string it finds that contains a b.

Fix restricting file mode matching

deadalnix requested changes to this revision.Sep 3 2020, 18:11

I have no idea what problem this fixes.

Sure, this match different things. Ok. Why should it match these things? What problem happens when it doesn't?

  1. [^,]*, Only matches one comma, so calls to open() where the first arg is composed of other calls (in the above example, it's os.path.join(os.path.dirname(__file__), 'resources', 'teamcity-icon-16.base64')), the match is incorrect.
  2. I misread the [^'\"] and should have removed it. Will fix. The new matching intends to restrict the file mode matching so that it doesn't just match the first string it finds that contains a b.

You are explaining the code to me. I do not care about the code, I want to know what the problem is with this code. This needs to be part of the description.

If not for me, then for whoever is going to dig in the history of that whole thing trying to figure out WTF is going on.

This revision now requires changes to proceed.Sep 3 2020, 18:11

Completely rewrote the summary to focus on the problem being solved. The code change mostly speaks for itself.

This revision is now accepted and ready to land.Sep 3 2020, 21:37