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

Update Python union and optional types to use | syntax #4338

Closed
1 of 2 tasks
Tracked by #5880
VIKTORVAV99 opened this issue Jul 11, 2022 · 2 comments · Fixed by #5882
Closed
1 of 2 tasks
Tracked by #5880

Update Python union and optional types to use | syntax #4338

VIKTORVAV99 opened this issue Jul 11, 2022 · 2 comments · Fixed by #5882
Assignees
Labels
python Pull requests that update Python code techdebt Unpleasantness that does (or may in future) affect development

Comments

@VIKTORVAV99
Copy link
Member

VIKTORVAV99 commented Jul 11, 2022

The current type syntax is not very user friendly, we should update all the types to use type1 | type2 instead of Union[type1, type2] and type | null instead of Optional[type] as soon as possible.

Another benefit of this is that we get less imports as the new type deceleration is native and don't rely on importing Union or Optional from typing.

@VIKTORVAV99 VIKTORVAV99 self-assigned this Jul 11, 2022
@VIKTORVAV99 VIKTORVAV99 added python Pull requests that update Python code techdebt Unpleasantness that does (or may in future) affect development labels Jul 11, 2022
xmichele added a commit to xmichele/electricitymap-contrib that referenced this issue Jul 29, 2022
Hello, congrats for the interesting project.
Here you find the mod that include:
- upgrade to python 3.10 (electricitymaps#4338)
- upgraded debian slim version + instructions to reduce image footprint (lowered to 1.42GB quite 1GB less than the current one!)
- more security and less surface attack thanks to the upgraded & slim version of the base image
@VIKTORVAV99 VIKTORVAV99 changed the title Update Python union types to use | syntax Update Python union and optional types to use | syntax Jul 30, 2022
@shuuji3
Copy link
Contributor

shuuji3 commented Jul 31, 2022

Have you tried a helpful tool called pyupgrade? It can automatically rewrite Union and Option to new type notation with --py310-plus flag: https://github.com/asottile/pyupgrade/#pep-604-typing-rewrites.

Also, I can perform other refactorings like the conversion from str.format() to f-string. It looks like it always works perfectly but it can reduce manual work and error for refactoring.

@VIKTORVAV99
Copy link
Member Author

Have you tried a helpful tool called pyupgrade? It can automatically rewrite Union and Option to new type notation with --py310-plus flag: https://github.com/asottile/pyupgrade/#pep-604-typing-rewrites.

Also, I can perform other refactorings like the conversion from str.format() to f-string. It looks like it always works perfectly but it can reduce manual work and error for refactoring.

The problem isn't really the refactoring itself but I'm waiting for #4335 and #4337 before I do anything.

However that tool looks interesting so I'll keep it in mind when this is ready to be fixed.

@VIKTORVAV99 VIKTORVAV99 added the BLOCKED Waiting on other task or external factors label Jul 31, 2022
@VIKTORVAV99 VIKTORVAV99 removed the BLOCKED Waiting on other task or external factors label Sep 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
python Pull requests that update Python code techdebt Unpleasantness that does (or may in future) affect development
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants