4 ms·
1) the code you wrote isn’t Python. 2) inferring the type is int isn’t guaranteed to be correct in this case
by jsjohnst 1y ago
1) the code you wrote isn’t Python.
2) inferring the type is int isn’t guaranteed to be correct in this case
- toolslive 1y agoI was merely giving an example that strong typing has nothing to do with having to write the types. (and, obviously, the inferred type (int -> int) is correct. )
- Izkata 1y agoOnly if reveal_type only accepts an int. Just because the default value of i is 0 doesn't mean anything about what could be passed in.
- toolslive 1y agonot my fault python is broken.
- jsjohnst 1y ago> and, obviously, the inferred type (int -> int) is correct. No it’s not. It’s Optional[int] -> int at minimum. There are other completely valid signatures beyond that too.
- int_19h 1y agoIt's guaranteed to be correct if you use different operators for ints and floats, which is what at least some ML dialects (notably, OCaml) do precisely so that types can be inferred from usage. That's the downside of operator overloading - since it relies on types to resolve, they need to be known and can't be inferred.