I needed the array indices to be int64 and specified them as such during initialization.
Downstreams, however, it would look at the actual index values and dynamically cast them to int32 if it judged there would be no loss in precision. This would completely screw up the roundtrip through a module implemented in C.
Being an intermittent bug it was quite a hell.
You don’t know but you are addicted to types
Come to the light - Haskell!
Or embrace logic + functional programming: Curry. https://curry-language.org/
def f(i=0) -> None:
j = i + 1
k = 1
reveal_type(i)
reveal_type(j)
reveal_type(k)
Output: Revealed type is "Any"
Revealed type is "Any"
Revealed type is "builtins.int"int -> int
Is wrong. At minimum it’s:
Optional[int] -> int
Because you provided a default value so clearly it’s not required to provide an input parameter. It’s also wrong to assume `0` is an int. There’s other valid types it could be. If the default was say `42`, I’d be pushing back a little less (outside of the Optional part), but this contrived example from GP had 0, which is ambiguous on what the inferred typing must be.
def f(i=0) -> None:
reveal_type(i)
The inferred type is not `float` nor `int`, but `Any`. Mypy will happily let you call `f("some string")`.Pyright correctly deduces the type as int.
In any case it's a bad example as function signatures should always be typed.
> # fun x -> x + 1;;
> - : int -> int = <fun>
>2) inferring the type is int isn’t guaranteed to be correct in this case
No it’s not. It’s Optional[int] -> int at minimum. There are other completely valid signatures beyond that too.
That's the downside of operator overloading - since it relies on types to resolve, they need to be known and can't be inferred.
It could be:
def f(i=0) -> None:
if i is None:
do_something()
else:
do_something_else()
Yeah, I know it's retarded. I don't expect high quality code in a code base missing type annotation like that. Assuming `i` is `int` or `float` just makes incrementally adoption of a type checker harder.I mentioned pyright because (some of) the specific concerns by OP are addressed by it.
Pyright probably works if you use it for a new project from the start or invest a lot of time "fixing" an existing project. But it's a totally different tool and it's silly to criticise mypy without understanding its use case.
I tried Pyright but as you say on an existing project you need a looot of time to "fix" it.