Fixed: Code style and lint fixes #1261
No reviewers
Labels
No Label
bug
build
dependencies
developers
documentation
duplicate
enhancement
formatting
invalid
legal
mobile
obsolete
packaging
performance
protocol
question
refactoring
regression
security
test
translation
usability
wontfix
No Milestone
No project
No Assignees
1 Participants
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: Bitmessage/PyBitmessage-2024-12-11#1261
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "codeQ-2105"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Address code style and lint violations in the next two most violating files.
Of interest for testing would be the change to imports. The app runs for me but my testing procedure is not thorough yet.
@ -10,1 +15,3 @@
disable=invalid-name,bare-except
disable=invalid-name,bare-except,broad-except
# invalid-name: needs fixing during a large, project-wide refactor
# bare-except,broad-except: Need fixing once thorough testing is easier
So you disable the warnings about except without exception type totally?
@ -24,3 +35,4 @@
# Service flags
NODE_NETWORK = 1
NODE_SSL = 2
NODE_DANDELION = 8
It seems to be safe to sort these standard library imports. Not sure about the local imports below. Did you test?
Maybe this comment should be retained or
# Bitfield
above deleted?This should be retained IMHO. It looks like section mark.
@ -253,7 +294,9 @@ def assembleVersionMessage(remoteHost, remotePort, participatingStreams, server
return CreatePacket('version', payload)
Again, brackets are redundant here. Also I'd prefer formatting like:
because in this case the continuation line is better seen
Next section...
Maybe can you break the line and remove these
\
@ -393,3 +451,4 @@
endOfLifeTime)
return 0
intObjectType, = unpack('>I', data[16:20])
try:
Same considerations about brackets and exc_info here and above...
Maybe use
exc_info=True
instead?Maybe
-3600
should be here. That minus is not binary operator.@ -91,3 +124,1 @@
ripemd160 = hashlib.new('ripemd160')
ripemd160.update(intermed)
return ripemd160.digest()
intermed = hashlib.sha256(string).digest()
Strange call.
base10_double()
is defined for only one arg below.@ -91,3 +124,1 @@
ripemd160 = hashlib.new('ripemd160')
ripemd160.update(intermed)
return ripemd160.digest()
intermed = hashlib.sha256(string).digest()
@PeterSurda this looks like unused code
Reluctant to do this as part of code quality / lint work. If you open an issue I'll take a look into this separately.
Fix incoming.
@ -253,7 +294,9 @@ def assembleVersionMessage(remoteHost, remotePort, participatingStreams, server
return CreatePacket('version', payload)
OK, change incoming.
@ -393,3 +451,4 @@
endOfLifeTime)
return 0
intObjectType, = unpack('>I', data[16:20])
try:
Changed to the string formatting incoming, same issue with changing fuctionality here.
This was already there, in 2.7.13 it seems to do the right thing. Again, raise an issue and I'll check the history of this, perhaps older versions we still support handle it differently so I'm reluctant to change it as part of a style / lint commit.
Section markers returning in next commit. I'd prefer separate files for different concerns.
Section markers returning in next commit
@ -253,7 +294,9 @@ def assembleVersionMessage(remoteHost, remotePort, participatingStreams, server
return CreatePacket('version', payload)
incoming
@ -10,1 +15,3 @@
disable=invalid-name,bare-except
disable=invalid-name,bare-except,broad-except
# invalid-name: needs fixing during a large, project-wide refactor
# bare-except,broad-except: Need fixing once thorough testing is easier
I have explained this issue several times during these cleanup commits. I am unable to fully test which exceptions might be thrown without a more thorough testing setup. If you know for sure which exceptions may be thrown at each bare/broad except then please fill them in and you can take the abuse for any runtime failures that crop up. We know that we have to fix the disabled checks, we're just not doing it now.
@ -24,3 +35,4 @@
# Service flags
NODE_NETWORK = 1
NODE_SSL = 2
NODE_DANDELION = 8
I tested that the gui ran but my test setup is lacking. As I said in the PR description,
Of interest for testing would be the change to imports. The app runs for me but my testing procedure is not thorough yet.
@ -91,3 +124,1 @@
ripemd160 = hashlib.new('ripemd160')
ripemd160.update(intermed)
return ripemd160.digest()
intermed = hashlib.sha256(string).digest()
Try an list of two items:
Although the function is unused (except by arithmetic.base10_add()) there are other functions in there that are not used as well. While removing cruft does fall under linting, I'd argue that applies to our cruft and that we should be using the pyelliptic library rather than copy/pasting it into our code and hacking it.
Perhaps we could open an issue to deal with this separately? Updates to upstream would be easier to manage if we add a dependency or left the code as-is to allow copy/paste from upstream. Having to copy/paste from upstream when we've hacked the files makes updating harder.
If you read this and still want the unused code removing, I will do.
@ -91,3 +124,1 @@
ripemd160 = hashlib.new('ripemd160')
ripemd160.update(intermed)
return ripemd160.digest()
intermed = hashlib.sha256(string).digest()
It looks like this bug is in upstream since day 1.
@ -10,1 +15,3 @@
disable=invalid-name,bare-except
disable=invalid-name,bare-except,broad-except
# invalid-name: needs fixing during a large, project-wide refactor
# bare-except,broad-except: Need fixing once thorough testing is easier
I don't request you to add exception types. But I don't like an idea to mask any issue which you cannot resolve immediately. Let lint warn.
@ -24,3 +35,4 @@
# Service flags
NODE_NETWORK = 1
NODE_SSL = 2
NODE_DANDELION = 8
OK, at least my tests doesn't fail: https://travis-ci.org/g1itch/PyBitmessage/builds/383283944
My remark was exactly about style: I think the space is redundant here. No doubt that works correctly in any python interpreter.
@ -10,1 +15,3 @@
disable=invalid-name,bare-except
disable=invalid-name,bare-except,broad-except
# invalid-name: needs fixing during a large, project-wide refactor
# bare-except,broad-except: Need fixing once thorough testing is easier
I understand where you're coming from regarding masking warnings. However, there are exactly three lint warnings that are disabled project-wide: invalid-name, bare-except and broad-except. Invalid name will be fixed with a project-wide refactor of names once the other style and lint issues are fixed, the other two require me to have a better test process.
In the meantime we can use the return status of
fab code_quality
to ensure, as part of our CI and/or git hooks, that we don't regress in terms of code quality. Once we have those lint warnings (that are currently disabled) fixed, the only thing left is the lines that are between 80 and 119 characters, which can be fixed as we go, or when we're slack.If I were thinking like you are now I would be much more concerned with the three lines worth of lint warnings that I have disabled at the top of the most offending modules. These require serious refactoring in terms of the structure of the module. It cannot be done without a rigorous testing process, I cannot do it personally until I understand the code better. Rest assured, it will be done.
Edit:For example, if we had a 'must not increase violation count' hook and re-enabled the invalid-name check we would never be able to add a line involving a variable namedInCamelCase.
No doubt? The linters didn't pick it up. Nor autopep8. So
-3600
can't be the canonical version. I'm going assume they know something I don't until I investigate. They have a lot of bugs though, so this could be one of them. Please, raise an issue, assign it to me and I promise I will investigate.The style I was aiming for here (at Peter's direction) was one that passed codacy but evolved (via github discussion) into one that passes multiple linters.
I don't want to bike-shed about things like hanging brackets in lists/dicts and functions (I like de-dented closes for data and long functions and trailing ones for short functions) or single line #-comments above a line vs a triple-quoted string below (sphinx likes the latter) or the number of statements between single blank lines (I like about 6).
I'm all in favour of us voting on which further, voluntary conventions to stick to. And I will stick to the ones that I don't even like for the sake of the consistency of the project. A consistent project is better than an inconsistent project. But then again, a happy developer is better than an unhappy developer ;)
@ -91,3 +124,1 @@
ripemd160 = hashlib.new('ripemd160')
ripemd160.update(intermed)
return ripemd160.digest()
intermed = hashlib.sha256(string).digest()
Upstream is abandoned, sadly. We have to carry the flag.