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

PEP 604 Optional[] #199

Open
Spirit412 opened this issue Dec 13, 2023 · 3 comments
Open

PEP 604 Optional[] #199

Spirit412 opened this issue Dec 13, 2023 · 3 comments

Comments

@Spirit412
Copy link

Python 3.10+ introduces the | union operator into type hinting, see PEP 604. Instead of Union[str, int] you can write str | int. In line with other type-hinted languages, the preferred (and more concise) way to denote an optional argument in Python 3.10 and up, is now Type | None, e.g. str | None or list | None.

I'm sure many people use version 3.10 and higher.
Also, the List type changes to list
I suggest you bring the code to PEP 604 or make an option during installation

@s3rius
Copy link
Owner

s3rius commented Dec 15, 2023

I guess that simplest way to acomplish this is to write an additional script that would reformat the code with PEP604.

@Spirit412
Copy link
Author

Павел, можно ли приведение кода к PEP604 реализовать на линтере?

@s3rius
Copy link
Owner

s3rius commented Dec 15, 2023

Pavel, is it possible to convert the code to PEP604 using a linter?

Maybe. Here's ruff's docs on the feature. But the automatic fix is marked as unstable.

Also, I guess we need to switch to ruff. So this feature might be easily turned on by users.

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

No branches or pull requests

2 participants