electricitymaps-contrib icon indicating copy to clipboard operation
electricitymaps-contrib copied to clipboard

Update Python union and optional types to use `|` syntax

Open VIKTORVAV99 opened this issue 3 years ago • 2 comments

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.

  • [ ] #4337
  • [ ] Update types

VIKTORVAV99 avatar Jul 11 '22 17:07 VIKTORVAV99

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.

shuuji3 avatar Jul 31 '22 11:07 shuuji3

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 avatar Jul 31 '22 16:07 VIKTORVAV99