Type hinting for Python
Type hinting for Python
Posted Jan 8, 2015 17:39 UTC (Thu) by deepfire (guest, #26138)In reply to: Type hinting for Python by pboddie
Parent article: Type hinting for Python
What I was saying is -- there's no known way to assign types to all expressions of Python. AFAIK, that's the standard lingo in type theory.
> Meanwhile, how would "typechecking on module load" work?
I'm sorry, that was a careless choice of words on my part. What I meant, instead, is just compile-time (AST -> code-object) type checking.
> ..but there's a risk of it ending up in a type specification swamp
> whilst not managing to offer something as mature as (or with the
> inferencing conveniences of) something like OCaml or various other
> functional languages.
This is exactly how I feel, indeed.
Posted Jan 8, 2015 22:45 UTC (Thu)
by pboddie (guest, #50784)
[Link] (1 responses)
I've had a fascination for Python code analysis over many years, and things like deducing types can work provided that certain constraints are enforced. Part of the problem is actually being able to conclusively describe the types, and Python always manages to provide loopholes that could, at least in theory, undermine such descriptions and undo all the resulting deductions about the code.
But given some constraints on the language, you can make deductions about types in programs, even reliable ones if the loopholes are eliminated. Some people get upset about this because "it's not Python any more!" but no-one appears to be interested in discussing the nature of Python beyond what's in the Python-3.x.tar.gz file on python.org.
As a result, we now have type annotations requiring a new vocabulary to describe types when it may well be the case that there are more substantial gains to be made in actually simplifying or structuring other aspects of the language, at least for those interested in increased reliability or predictability of Python programs.
Posted Jan 9, 2015 18:33 UTC (Fri)
by deepfire (guest, #26138)
[Link]
As to typing.. why bother with this painful shoe-horning, when there are
--
Type hinting for Python
Type hinting for Python
since there Common Lisp beats it in almost all departments, except syntax unobtrusiveness.
Tangentially, CL also has optional type annotations, and modern CL compilers do a fairly
useful job at partial type inference, and even provide optimization hints.
beautiful static, inferred, optionally-enforcing[1] languages like Haskell..
1. As of 7.8 GHC gained an option to defer type errors to runtime