Skip to content
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

Fix flake8 issue WPS336 (explicit str concat) #254

Merged
merged 24 commits into from
Dec 27, 2019

Conversation

alephnot0
Copy link
Contributor

@alephnot0 alephnot0 commented Dec 3, 2019

❓ What kind of change does this PR introduce?

  • 🐞 bug fix
  • 🐣 feature
  • πŸ“‹ docs update
  • πŸ“‹ tests/coverage improvement
  • πŸ“‹ refactoring
  • πŸ’₯ other

πŸ“‹ What is the related issue number (starting with #)

#253 - flake8 style cleanup.

❓ What is the current behavior? (You can also link to an open issue here)

➜  cheroot git:(master) βœ— flake8 . | grep WPS336
./cheroot/server.py:159:33: WPS336 Found explicit string concat
./cheroot/server.py:470:30: WPS336 Found explicit string concat
./cheroot/server.py:825:47: WPS336 Found explicit string concat
./cheroot/server.py:1041:20: WPS336 Found explicit string concat
./cheroot/server.py:1502:15: WPS336 Found explicit string concat
./cheroot/server.py:1808:32: WPS336 Found explicit string concat
./cheroot/wsgi.py:303:14: WPS336 Found explicit string concat
./cheroot/wsgi.py:412:36: WPS336 Found explicit string concat
./cheroot/test/test_conn.py:841:12: WPS336 Found explicit string concat
./cheroot/test/test_conn.py:841:40: WPS336 Found explicit string concat
./cheroot/test/test_conn.py:975:15: WPS336 Found explicit string concat
./cheroot/test/test_ssl.py:192:9: WPS336 Found explicit string concat
./cheroot/test/test_ssl.py:192:34: WPS336 Found explicit string concat
./cheroot/test/test_ssl.py:192:52: WPS336 Found explicit string concat
./cheroot/test/test_ssl.py:277:13: WPS336 Found explicit string concat
./cheroot/test/test_ssl.py:277:38: WPS336 Found explicit string concat
./cheroot/test/test_ssl.py:277:56: WPS336 Found explicit string concat
./cheroot/test/test_ssl.py:485:13: WPS336 Found explicit string concat
./cheroot/test/test_ssl.py:485:32: WPS336 Found explicit string concat
./cheroot/test/test_ssl.py:485:50: WPS336 Found explicit string concat
./cheroot/test/test_ssl.py:496:13: WPS336 Found explicit string concat
./cheroot/test/test_ssl.py:496:32: WPS336 Found explicit string concat
./cheroot/test/test_ssl.py:496:50: WPS336 Found explicit string concat
./cheroot/workers/threadpool.py:179:28: WPS336 Found explicit string concat
./cheroot/workers/threadpool.py:226:24: WPS336 Found explicit string concat

❓ What is the new behavior (if this is a feature change)?

➜  cheroot git:(master) flake8 . | grep WPS336
➜  cheroot git:(master) 

πŸ“‹ Other information:

πŸ“‹ Checklist:

  • I think the code is well written
  • I wrote good commit messages
  • I have squashed related commits together after the changes have been approved
  • Unit tests for the changes exist
  • Integration tests for the changes exist (if applicable)
  • I used the same coding conventions as the rest of the project
  • The new code doesn't generate linter offenses
  • Documentation reflects the changes
  • The PR relates to only one subject with a clear title
    and description in grammatically correct, complete sentences

This change is Reviewable

@codecov
Copy link

codecov bot commented Dec 3, 2019

Codecov Report

Merging #254 into master will decrease coverage by 1.21%.
The diff coverage is 72.72%.

@@            Coverage Diff             @@
##           master     #254      +/-   ##
==========================================
- Coverage   78.35%   77.13%   -1.22%     
==========================================
  Files          25       25              
  Lines        3816     3727      -89     
==========================================
- Hits         2990     2875     -115     
- Misses        826      852      +26

msg = self.server.protocol.encode('ascii')
msg += b' 100 Continue\r\n\r\n'
msg = b''.join([self.server.protocol.encode('ascii'),
b' 100 Contunue\r\n\r\n'])
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
b' 100 Contunue\r\n\r\n'])
b' 100 Continue\r\n\r\n'])

msg = self.server.protocol.encode('ascii')
msg += b' 100 Continue\r\n\r\n'
msg = b''.join([self.server.protocol.encode('ascii'),
b' 100 Contunue\r\n\r\n'])
Copy link
Member

Choose a reason for hiding this comment

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

But better use string interpolation because it would be better readable this way.
Like

b'{} {}'.format(
    self.server.protocol.encode('ascii'),
    b' 100 Continue\r\n\r\n',
)

Copy link
Member

@webknjaz webknjaz left a comment

Choose a reason for hiding this comment

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

Thanks for the PR. It is better to prefer newer and faster str.format() over the %-interpolation syntax. Would you mind doing this?

@webknjaz
Copy link
Member

webknjaz commented Dec 3, 2019

@alephnot0 it looks like your Git is misconfigured: the commits you submitted have author email that doesn't match your GitHub account. You may want to fix that as well.

@alephnot0
Copy link
Contributor Author

@webknjaz no I wouldn't mind, thanks for the feedback.

@lgtm-com
Copy link

lgtm-com bot commented Dec 4, 2019

This pull request introduces 1 alert and fixes 3 when merging 1e7a23b into 85a190f - view on LGTM.com

new alerts:

  • 1 for Syntax error

fixed alerts:

  • 2 for Unused local variable
  • 1 for __init__ method calls overridden method

@lgtm-com
Copy link

lgtm-com bot commented Dec 4, 2019

This pull request introduces 1 alert and fixes 3 when merging 3afec78 into 85a190f - view on LGTM.com

new alerts:

  • 1 for Syntax error

fixed alerts:

  • 2 for Unused local variable
  • 1 for __init__ method calls overridden method

cheroot/server.py Outdated Show resolved Hide resolved
cheroot/server.py Outdated Show resolved Hide resolved
cheroot/server.py Outdated Show resolved Hide resolved
cheroot/server.py Outdated Show resolved Hide resolved
cheroot/server.py Outdated Show resolved Hide resolved
@@ -838,7 +838,8 @@ def test_Chunked_Encoding(test_client):

# Try a chunked request that exceeds server.max_request_body_size.
# Note that the delimiters and trailer are included.
body = b'3e3\r\n' + (b'x' * 995) + b'\r\n0\r\n\r\n'
body = '{}{}{}'.format('3e3\r\n', 'x' * 995, '\r\n0\r\n\r\n') \
.encode('ascii')
Copy link
Member

Choose a reason for hiding this comment

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

Please use proper literals instead of heavy encode/decode methods. It's also a good place for bytes.join(). Same with escaping EOL.

@@ -971,8 +972,8 @@ def test_No_CRLF(test_client, invalid_terminator):
# Initialize a persistent HTTP connection
conn = test_client.get_connection()

# (b'%s' % b'') is not supported in Python 3.4, so just use +
conn.send(b'GET /hello HTTP/1.1' + invalid_terminator)
conn.send('GET /hello HTTP/1.1{}'.format(invalid_terminator)
Copy link
Member

Choose a reason for hiding this comment

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

We work with bytes so we need to explicitly say that it's bytes.

cheroot/wsgi.py Outdated
@@ -300,7 +300,7 @@ def get_environ(self):

# Request headers
env.update(
('HTTP_' + bton(k).upper().replace('-', '_'), bton(v))
('HTTP_%s' % (bton(k).upper().replace('-', '_')), bton(v))
Copy link
Member

Choose a reason for hiding this comment

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

Use str.format() in this module.

@webknjaz webknjaz changed the title [style] Address flake8 issue WPS336 - Found explicit string concat Fix flake8 issue WPS336 (explicit str concat) Dec 27, 2019
@webknjaz webknjaz merged commit bd0f6d2 into cherrypy:master Dec 27, 2019
@alephnot0
Copy link
Contributor Author

@webknjaz thank you for merging. I will be continuing to contribute as I have time.

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.

2 participants