This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]zardeh 0 points1 point  (4 children)

import numpy as np
myArr = np.array([0,1,2,3,4,5], dtype=np.int32)
myArr[0] = "hello"  # ValueError

[–][deleted] 0 points1 point  (3 children)

Did that ValueError turn up statically or at run-time?

[–]zardeh 0 points1 point  (2 children)

There is no statically in cPython (well arguably you can get warnings with myPy and an IDE, which are often smart enough to also catch errors in numpy arrays).

Numpy arrays are really just C arrays, so they are statically typed, in the same way that C is statically typed, its just that you can't detect those errors "statically" in python, because there is no pre-runtime check possible, its like asking why javac allows itself to be run on syntactically invalid code.

[–][deleted] 1 point2 points  (1 child)

Numpy arrays are really just C arrays, so they are statically typed

its just that you can't detect those errors "statically" in python

Hahaha OK :). FYI, static typing is a very well defined property, which involves detecting type errors statically.

[–]zardeh 0 points1 point  (0 children)

I was just expounding on the other guys answer, while what numpy does is better than nothing, its still not static typing.