Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Run pyupgrade for python 3.7 & 3.8. #16110

Merged
merged 4 commits into from Aug 15, 2023
Merged

Run pyupgrade for python 3.7 & 3.8. #16110

merged 4 commits into from Aug 15, 2023

Conversation

clokep
Copy link
Contributor

@clokep clokep commented Aug 14, 2023

Two commits running pyupgrade --py37-plus --keep-percent-format **/*.py, then pyupgrade --py38-plus --keep-percent-format **/*.py.

(Note that ruff seems to now support using pyupgrade, but I had issues enabling it.)

@clokep clokep marked this pull request as ready for review August 14, 2023 13:00
@clokep clokep requested a review from a team as a code owner August 14, 2023 13:00
Comment on lines +29 to +32
# 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):
Copy link
Contributor Author

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?

synapse/handlers/sso.py Show resolved Hide resolved
from typing import (
TYPE_CHECKING,
Any,
Counter as CounterType,
Copy link
Contributor

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),))
Copy link
Contributor

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.

Copy link
Contributor Author

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:

  1. Function call
  2. Grouping (unneeded)
  3. Tuple
  4. 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
Copy link
Contributor

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(),
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes.

@clokep clokep merged commit ad3f43b into develop Aug 15, 2023
37 checks passed
@clokep clokep deleted the clokep/pyupgrade branch August 15, 2023 12:11
H-Shay pushed a commit that referenced this pull request Aug 16, 2023
@V02460 V02460 mentioned this pull request Aug 19, 2023
4 tasks
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants