-
Notifications
You must be signed in to change notification settings - Fork 27
Description
Describe the bug
Currently, our autoformatters replace instances of Optional[ConcreteType]
with ConcreteType | None
. This results in a loss of clarity for expectations regarding ImplicitDict fields. For instance, this is more clear:
class Foo(ImplicitDict):
baz: Optional[str]
...than
class Bar(ImplicitDict):
baz: str | None
When a user is considering what to provide to populate the baz
field, the Foo class type annotation reads as "this field may optionally contain a str" with the implication that it doesn't need to be provided since it's optional. The Bar class type annotation reads as "this field may be a str or it may be None" with the implication that a value with one of these types needs to be provided.
To reproduce
- Write an ImplicitDict class declare one or more fields with
Optional[ConcreteType]
type - Run
make format
- Observe that the fields have been rewritten to have the type
ConcreteType | None
Difference from expected behavior
I expect to be able to annotate ImplicitDict fields as being optional using the word "Optional".