-
-
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
Small Pythonic code changes for datastructures.py file #1167
Merged
Kludex
merged 6 commits into
encode:master
from
ShahriyarR:datastructures-code-refactoring
Jun 11, 2021
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
183a6f5
Small Pythonic code changes for datastructures.py file
ShahriyarR 4d73416
Reverting back .gitignore changes
ShahriyarR 05011f6
reverting back newline in .gitignore
ShahriyarR 47aa180
Reverting back the changes as requested during merge review
ShahriyarR b198ee3
Merge branch 'master' into datastructures-code-refactoring
Kludex 7709471
Merge branch 'master' into datastructures-code-refactoring
Kludex File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,3 +11,6 @@ venv*/ | |
.python-version | ||
build/ | ||
dist/ | ||
.idea/ | ||
.venv/ | ||
.vscode/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -180,11 +180,7 @@ def make_absolute_url(self, base_url: typing.Union[str, URL]) -> str: | |
else: | ||
scheme = base_url.scheme | ||
|
||
if self.host: | ||
netloc = self.host | ||
else: | ||
netloc = base_url.netloc | ||
|
||
netloc = self.host or base_url.netloc | ||
path = base_url.path.rstrip("/") + str(self) | ||
return str(URL(scheme=scheme, netloc=netloc, path=path)) | ||
|
||
|
@@ -246,11 +242,7 @@ def __init__( | |
) -> None: | ||
assert len(args) < 2, "Too many arguments." | ||
|
||
if args: | ||
value = args[0] | ||
else: | ||
value = [] | ||
|
||
value = args[0] if args else [] | ||
if kwargs: | ||
value = ( | ||
ImmutableMultiDict(value).multi_items() | ||
|
@@ -584,10 +576,11 @@ def __setitem__(self, key: str, value: str) -> None: | |
set_key = key.lower().encode("latin-1") | ||
set_value = value.encode("latin-1") | ||
|
||
found_indexes = [] | ||
for idx, (item_key, item_value) in enumerate(self._list): | ||
if item_key == set_key: | ||
found_indexes.append(idx) | ||
found_indexes = [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is controversial. Not everybody believes it's an improvement. I'd prefer to not change it. |
||
idx | ||
for idx, (item_key, item_value) in enumerate(self._list) | ||
if item_key == set_key | ||
] | ||
|
||
for idx in reversed(found_indexes[1:]): | ||
del self._list[idx] | ||
|
@@ -604,10 +597,11 @@ def __delitem__(self, key: str) -> None: | |
""" | ||
del_key = key.lower().encode("latin-1") | ||
|
||
pop_indexes = [] | ||
for idx, (item_key, item_value) in enumerate(self._list): | ||
if item_key == del_key: | ||
pop_indexes.append(idx) | ||
pop_indexes = [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. |
||
idx | ||
for idx, (item_key, item_value) in enumerate(self._list) | ||
if item_key == del_key | ||
] | ||
|
||
for idx in reversed(pop_indexes): | ||
del self._list[idx] | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Those ignores are not going to be accepted 😅
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 tried: encode/uvicorn#1001
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.
ahahaha :D Okay reverting back)
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.
Done