Union with None / NoneType type does not behave as expected
- Dominant language
- Python
- Stars
- 16.8k
- Forks
- 603
- Avg merge
- 4d 23h
- Merged PRs (30d)
- 6
Description
I have a function with this signature:
```
def get_value(self)-> Union[NoneType, bool, i32, i64, float, str]:
```
Sometime this function returns None
When this happens, printing a returned value results in this :
```
ValueError: optional unpack failed: expected Union[Int[32] | Int[64] | NoneType | bool | float | str], got None
Raised from: std.internal.types.optional.unwrap.0:0
/Users/yfinkelstein/.codon/lib/codon/stdlib/internal/types/optional.codon:99:5
```
Is there a better way to model a return type that has a nuber of type alternatives or None ?
Also, another strange behavior:
if the function does not return anything ( a branch that does not have a return statement and just exits), the returned value has the type of the first template type in the Union after sorting by type name
Contributor guide
Assessment
This issue has not been assessed yet.