-
-
Notifications
You must be signed in to change notification settings - Fork 953
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
refactor(util.uri): refactor dict comprehension #1783
Conversation
I'm definitely -1 on the static method thing. |
Another comment unrelated to the use of Sorry to be blunt, but refactoring |
@@ -49,9 +49,9 @@ | |||
_HEX_DIGITS = '0123456789ABCDEFabcdef' | |||
|
|||
# This map construction is based on urllib's implementation | |||
_HEX_TO_BYTE = dict(((a + b).encode(), bytes([int(a + b, 16)])) | |||
_HEX_TO_BYTE = {(a + b).encode(): bytes([int(a + b, 16)]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this change we could actually keep. The old form probably could not use dict comprehension because it had to support Python 2.6.
tests/test_sinks.py
Outdated
@@ -23,8 +24,7 @@ def __call__(self, req, resp, **kwargs): | |||
|
|||
|
|||
class SinkAsync(Sink): | |||
async def __call__(self, req, resp, **kwargs): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reimplementing __call__
is intended here (note the change from sync to async
).
Tbh, this looks like a bug in DeepSource if the above is marked for refactoring.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you once again for this initiative to improve our code quality.
However, as discussed in the above comments, we do not want to indiscriminately refactor the following:
- Functions not making use of
self
➡️@staticmethod
.@staticmethod
may at times semantically make sense, but more often than not, it is not the case in our codebase. Moreover, it does not offer any speed improvement (it actually may even incur a slight penalty). assert
➡️ manually raising anAssertionError
in a branch statement -- we simply do not want this.elif
afterreturn
orraise
➡️if
. While I have nothing against the pattern itself, and actually use it, we need to discuss whether it is worth the effort (e.g., how do these alternatives compare performance wise?) refactoring. I.e., I'm actually not opposed to this one, but it is better to discuss this one separately.
I know it feels like harsh feedback... 👿 But could you roll back refactoring of the 3 above patterns, and we could take a look at what's left. As noted on the PR, there are some good changes that we could actually be willing to keep.
Notwithstanding potential improvements, you also have to get our CI to pass in order for a PR to be considered. Check how to run tox
or our mintest.sh
wrapper here: CONTRIBUTING.md
. Right now, it seems that some tests got broken because of refactoring, including the simplest of smoke tests.
Needless to say, @withshubh, You are also very welcome to discuss these changes with us on our Gitter channels!
Codecov Report
@@ Coverage Diff @@
## master #1783 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 54 54
Lines 5128 5128
Branches 823 823
=========================================
Hits 5128 5128
Continue to review full report at Codecov.
|
@withshubh just checking, if you are planning to continue work on this PR? And I'm sorry to be blunt (again), but an en masse |
Hi @vytas7 👋 It's okay for being blunt(again) 😛 I'll fix this and update the PR. ✨ |
Revert fixes breaking checks and fixes made using autopep8 transformer
Hi @vytas7 Please have a look. 👀 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see inline comments.
.deepsource.toml
Outdated
@@ -0,0 +1,10 @@ | |||
version = 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove this file.
We have not decided on using DeepSource yet.
falcon/util/structures.py
Outdated
@@ -61,7 +61,7 @@ class CaseInsensitiveDict(MutableMapping): # pragma: no cover | |||
|
|||
""" | |||
def __init__(self, data=None, **kwargs): | |||
self._store = dict() | |||
self._store = {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please read the comment on line 33 to understand why, and revert this change.
falcon/vendor/mimeparse/mimeparse.py
Outdated
@@ -98,7 +98,7 @@ def quality_and_fitness_parsed(mime_type, parsed_ranges): | |||
if type_match and subtype_match: | |||
|
|||
# 100 points if the type matches w/o a wildcard | |||
fitness = type == target_type and 100 or 0 | |||
fitness = 100 if type == target_type else 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let us revert these changes. Sensible they may be, we have vendored this module from https://github.com/dbtsai/python-mimeparse, and do not want to make any modifications unless absolutely necessary.
falcon/vendor/mimeparse/mimeparse.py
Outdated
@@ -181,7 +181,7 @@ def best_match(supported, header): | |||
pos += 1 | |||
weighted_matches.sort() | |||
|
|||
return weighted_matches[-1][0][0] and weighted_matches[-1][2] or '' | |||
return weighted_matches[-1][2] if weighted_matches[-1][0][0] else '' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let us revert these changes. Sensible they may be, we have vendored this module from https://github.com/dbtsai/python-mimeparse, and do not want to make any modifications unless absolutely necessary.
…ata structure, Replace ternary syntax with if expression
revert fix
Hi @vytas7 Now this PR contains just one fix:
I'd like to know what are your thoughts regarding integrating the DeepSource. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let us please address PEP8 violations before merging this PR:
./falcon/util/uri.py:53:21: E127 continuation line over-indented for visual indent
./falcon/util/uri.py:54:21: E127 continuation line over-indented for visual indent
Done @vytas7 ✨ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this!
Regarding DeepSource, my impression is that it is likely a very useful tool for a business project, or even a new open source library if DeepSource is agreed upon in advance.
However, for a highly specialized framework Falcon is, as you may have noticed, many "quality issues" exist there for a reason ("vendored" code, explicit test scenarios, deprecation strategies etc).
Moreover, another drawback is that DeepSource is not open, so we cannot easily integrate it into our offline development routines.
This PR fixes some of the quality issues raised by DeepSource on my fork of this repository.
Some of them are:
Take a quick look at all the issues caught by DeepSource for this repository here
Summary of Changes
Change methods not using its bound instance to staticmethodsuse literal syntax instead of function calls to create data structureremove assert statement from non-test filesrefactor unnecessary 'else' / 'elif' when 'if' block has a 'return' statementreplace ternary syntax with if expressionremove methods with unnecessary super delegationYou can also have a look at the configuration file I used for DeepSource Analysis.
If any of these issues that the DeepSource analysis found are critical for the codebase I'd suggest you to activate the analysis. You can trigger analysis on each PR once you integrate DeepSource in the repo. ⚡
Feel free to merge this PR if you wish to fix the issues.✨