On Fri, Aug 07, 2020 at 11:48:40PM -0400, David Mertz wrote:
On Fri, Aug 7, 2020, 6:03 PM Paul Moore firstname.lastname@example.org wrote:
x: int[0:] # any ints greater than or equal to zero would match, others
x: int[:101] # any ints less than 101 match x: int[0:101:2] # even less than 101
I suspect the biggest issue with this is that it's likely to be extremely hard (given the dynamic nature of Python) to check such type assertions statically.
Yes, it's hard in the sense that it would require solving the halting problem.
I don't see how static bounds checking would be fundamentally more difficult than static type checking. Static languages often check what bounds they can at compile time, and optionally insert bound checking runtime code for ambiguous places. See for example this comment:
""" 2.5 Static Analysis
Bounds checking has relied heavily on static analysis to optimize performance . Checks can be eliminated if it can be statically determined that a pointer is safe, i.e. always within bounds, or that a check is redundant due to a previous check """
I believe that JS++ does something similar:
and Checked C aims for similar compile-time bounds checking:
In any case, nobody expects to solve the Halting Problem for arbitrarily complex code. It is still useful to be able to detect some failures even if you can't detect them all: