Skip to content

Clean up linter failures #14

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
merged 5 commits into from
May 4, 2017
Merged

Clean up linter failures #14

merged 5 commits into from
May 4, 2017

Conversation

Lukasa
Copy link
Member

@Lukasa Lukasa commented May 4, 2017

Because I'm a weirdo I've decided to protect the master branch and also to require code reviews and stuff (I know, what a killjoy), but that gets a bit tricky when the linter is failing. So this is a very minor refactor of the code to get the linter back to passing, without breaking tests.

Sometime in the future I'll try to start creeping the test coverage upwards too. =)

@codecov-io
Copy link

codecov-io commented May 4, 2017

Codecov Report

Merging #14 into master will increase coverage by 0.12%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #14      +/-   ##
==========================================
+ Coverage   81.96%   82.09%   +0.12%     
==========================================
  Files           5        5              
  Lines         693      698       +5     
  Branches      163      163              
==========================================
+ Hits          568      573       +5     
  Misses         76       76              
  Partials       49       49
Impacted Files Coverage Δ
wsproto/frame_protocol.py 90.87% <100%> (+0.16%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0872c53...60deba5. Read the comment docs.

@sethmlarson
Copy link
Member

Is there a setting for codecov.yml that just disallows coverage to decrease?

@Lukasa
Copy link
Member Author

Lukasa commented May 4, 2017

I think we don't need it? I think the codecov/patch status fails if the coverage falls, and as it's a "Required" status we get the same effect. I think.

@sethmlarson
Copy link
Member

Ah that's probably the setting I was thinking about. :) Carry on!

elif payload_len == 127:
data = yield from self._consume_exactly(8)
(payload_len,) = struct.unpack("!Q", data)
if payload_len < 2 ** 16:
Copy link
Member

Choose a reason for hiding this comment

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

Could 2 ** 16 be converted to a constant?

Copy link
Member Author

Choose a reason for hiding this comment

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

It certainly could be, yeah. Not sure how much value there is in that though. It's possible, in fact, that python pre-compiles that value.

Copy link
Member Author

Choose a reason for hiding this comment

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

And in fact it does. Here's the output from dis.dis on this code, truncated to just cover line 157:

157         118 LOAD_FAST                2 (payload_len)
            120 LOAD_CONST              14 (65536)
            122 COMPARE_OP               0 (<)
            124 POP_JUMP_IF_FALSE      134

As you can see, something (probably Python's peephole optimiser) spots this static mathematical operation and compiles it into a single constant. So I don't think we need to worry about the conversion. =)

Copy link
Member

Choose a reason for hiding this comment

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

Oh not just from a speed perspective (although I didn't know Python had aggressive pre-compiling like that), also from a 'what-does-this-value-mean' perspective. I guess our audience is already knowledgeable about RFC 6455 so if we leave this value here it's fine with me. :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, so I get that. What isn't clear to me is whether this is clearer. I am not super familiar with RFC 6455, but this reads to me as being if payload_len < MAX_16_BIT_UINT. The exception on the next line basically acts as a code comment explaining what the check is. So, I don't know that the named constant would help much, if at all.

Copy link
Member

Choose a reason for hiding this comment

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

I agree, gotta remember our audience with this package. 😛

Copy link
Collaborator

Choose a reason for hiding this comment

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

So this is in section 5.2 of RFC 6455. The payload length can be expressed in three different ways and it's required that you use the one most appropriate. I agree that we should be using names here for comprehensibility purposes but the standard doesn't give us any obvious names. The values in question are:

  • 125 (Maximum normal (or short?) length)
  • 126 (Flag value for two-byte extended length)
  • 127 (Flag value for eight-byte extended length)
  • 2^16 (Maximum two-byte extended length)
  • 2^64 (Maximum eight-byte extended length)

I don't think the last one is used but having names for these would be handy. If I were to suggest some I'd probably go with:

PAYLOAD_LENGTH_TWO_BYTE = 126
PAYLOAD_LENGTH_EIGHT_BYTE = 127
MAX_PAYLOAD_LENGTH_SHORT = 125
MAX_PAYLOAD_LENGTH_TWO_BYTE = 2 ** 16
MAX_PAYLOAD_LENGTH_EIGHT_BYTE = 2 ** 64

I'm open to discussion though.

Copy link
Member

@sethmlarson sethmlarson left a comment

Choose a reason for hiding this comment

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

👍

@jeamland jeamland merged commit a65d3cd into master May 4, 2017
@Kriechi Kriechi deleted the clean-linter branch July 11, 2017 18:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants