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

Removing Deprecated Type Annotations #3318

Open
2 tasks
delliott0000 opened this issue Nov 27, 2023 · 0 comments
Open
2 tasks

Removing Deprecated Type Annotations #3318

delliott0000 opened this issue Nov 27, 2023 · 0 comments

Comments

@delliott0000
Copy link

Is your feature request related to a problem? Please elaborate.

This issue aims to improve the current state of Modmail's code.

As per the typing standard library docs, many types in the typing module have been deprecated since Python 3.9 in favor of their built-in counterparts. For example, typing.Tuple is now deprecated, and tuple should instead be used for such type annotations.

Furthermore, Python 3.10 and onwards supports the use of the | operator to define union types. Hence I'm also proposing that typing.Union and typing.Optional type annotations are replaced with the | operator, primarily for the sake of code readability.

To take an example from the project, typing.Tuple[discord.Message, typing.List[typing.Optional[discord.Message]]] would look like tuple[discord.Message, list[discord.Message | None]] after the change.

Since the project has recently dropped support for Python versions prior to 3.10, I think that now would be an appropriate time to make these changes. This change intends to make changes exclusively to various type annotations, therefore the bot's functionality and performance will remain unaffected.

Describe the solution you'd like

Import statements that are importing deprecated types from the typing module would be removed. Type annotations using these deprecated types would be replaced with their built-in counterparts (or the preferred alternative). typing.Union and typing.Optional are replaced with the | operator accordingly.

Changes would include, but are not necessarily limited to:

  • typing.List -> list
  • typing.Tuple -> tuple
  • typing.Optional and typing.Union -> ... | ...
  • typing.Sequence -> collections.abc.Sequence

Does your solution involve any of the following?

  • Logviewer
  • New config option

Describe alternatives you've considered

Nothing to add here.

Who will this benefit?

This change will primarily benefit core developers and maintainers of the project by improving code readability. It may also benefit plugin developers as well as people who are looking to fork the project and make their own changes.

Additional Information

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant