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

Small Pythonic code changes for datastructures.py file #1167

Merged
merged 6 commits into from
Jun 11, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ venv*/
.python-version
build/
dist/
.idea/
Copy link
Member

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 😅

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

@ShahriyarR ShahriyarR Apr 27, 2021

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

.venv/
.vscode/
30 changes: 12 additions & 18 deletions starlette/datastructures.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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 = [
Copy link
Member

Choose a reason for hiding this comment

The 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]
Expand All @@ -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 = [
Copy link
Member

Choose a reason for hiding this comment

The 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]
Expand Down