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

Use Literal from typing_extensions (compatible with Python 3.7)#15605

Closed
MadLittleMods wants to merge 2 commits intodevelopfrom
madlittlemods/15603-fix-literal-type
Closed

Use Literal from typing_extensions (compatible with Python 3.7)#15605
MadLittleMods wants to merge 2 commits intodevelopfrom
madlittlemods/15603-fix-literal-type

Conversation

@MadLittleMods
Copy link
Contributor

@MadLittleMods MadLittleMods commented May 15, 2023

Use Literal from typing_extensions (compatible with Python 3.7)

Fix the following mypy errors when running mypy with Python 3.7:

synapse/config/_base.pyi:2: error: Module "typing" has no attribute "Literal"  [attr-defined]

Part of #15603

typing.Literal is only available in Python 3.8 or later, https://docs.python.org/3/library/typing.html#typing.Literal

Pull Request Checklist

  • Pull request is based on the develop branch
  • Pull request includes a changelog file. The entry should:
    • Be a short description of your change which makes sense to users. "Fixed a bug that prevented receiving messages from other servers." instead of "Moved X method from EventStore to EventWorkerStore.".
    • Use markdown where necessary, mostly for code blocks.
    • End with either a period (.) or an exclamation mark (!).
    • Start with a capital letter.
    • Feel free to credit yourself, by adding a sentence "Contributed by @github_username." or "Contributed by [Your Name]." to the end of the entry.
  • Pull request includes a sign off
  • Code style is correct
    (run the linters)

Fix
```
synapse/config/_base.pyi:2: error: Module "typing" has no attribute "Literal"  [attr-defined]
```

`typing.Literal` is only available in Python 3.8 or later,
https://docs.python.org/3/library/typing.html#typing.Literal
)

import jinja2
from typing_extensions import Literal
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This PR is no longer necessary because we're now targeting Python 3.8 as the minimum version which is where typing.Literal was introduced.

But perhaps we want to do this solely to align our single typing.Literal usage to typing_extensions.Literal which we do everywhere else.

Or maybe we want to instead move everything to typing.Literal

Pokes in whatever direction welcome

Copy link
Member

Choose a reason for hiding this comment

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

I think move to typing.Literal ASAP when we drop 3.7 is the way to go

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.

2 participants