-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Conversation
# Note that we use an (unneeded) variable here so that pyupgrade doesn't nuke the | ||
# if-statement completely. | ||
py_version = sys.version_info | ||
if py_version < (3, 8): |
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.
Without this change pyupgrade
assumes you don't need this code and just removes it. Hopefully my comment is clear enough?
from typing import ( | ||
TYPE_CHECKING, | ||
Any, | ||
Counter as CounterType, |
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.
Looks like we should be able to just use collections.Counter[str]
in 3.9: https://docs.python.org/3/library/typing.html?highlight=typing%20protocol#typing.Counter
self._get_server_keys_json.invalidate((((server_name, key_id),))) | ||
self._get_server_keys_json.invalidate(((server_name, key_id),)) |
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 think this is safe: before we have invalidate( (t1) )
where t1 = (t2,)
. We are removing the inner brackets around t1
.
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.
Yeah, we have 4 sets of parens, if you expand it out you have:
- Function call
- Grouping (unneeded)
- Tuple
- Tuple
invalidate( #function call
( # grouping
( # tuple
( # tuple
server_name, key_id
),
)
)
)
@@ -38,7 +39,7 @@ | |||
from immutabledict import immutabledict | |||
from signedjson.key import decode_verify_key_bytes | |||
from signedjson.types import VerifyKey | |||
from typing_extensions import Final, TypedDict | |||
from typing_extensions import TypedDict |
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.
FWIW TypedDict was new in https://docs.python.org/3/library/typing.html?highlight=typeddict#typing.TypedDict , though there are various changes that were made in later Python releases
f"/_matrix/media/r0/download/{target}/{media_id}".encode("utf-8"), | ||
f"/_matrix/media/r0/download/{target}/{media_id}".encode(), |
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.
Presumably utf-8
is the default?
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.
Yes.
Two commits running
pyupgrade --py37-plus --keep-percent-format **/*.py
, thenpyupgrade --py38-plus --keep-percent-format **/*.py
.(Note that ruff seems to now support using pyupgrade, but I had issues enabling it.)