On Thu Jan 22 2015 at 6:19:38 AM Cem Karan <cfkaran2@gmail.com> wrote:
On Jan 21, 2015, at 11:47 PM, Guido van Rossum <guido@python.org> wrote:
On Wed, Jan 21, 2015 at 8:39 PM, Eugene Toder <eltoder@gmail.com> wrote: On Wed, Jan 21, 2015 at 8:25 PM, Greg Ewing <greg.ewing@canterbury.ac.nz> wrote: On 01/22/2015 01:50 PM, Guido van Rossum wrote: I've seen plenty of code that takes instances a certain class as argument and calls methods of that type but never constructs a new instance nor does any of the other things for which you need the class name,
If the only thing the name is needed for is static checking, I don't see what's so bad about not finding out until you actually run the static check. Adding those imports earlier doesn't make the code work any better or show up any more runtime bugs.
Also, if static type checking succeeds, it will be integrated into many IDEs/editors, so you will see type checker errors even before you get to run the tests.
So I think we're all agreed that the current proposal is fine!
*grumble* ;P
I know I keep arguing for a slightly different syntax so that its easy to differentiate between type hints and other uses, but I do want to say that I like the proposal. It seems quite practical to me. Would you at least consider adding something to the proposal that makes it clear that a given annotation is a type and not something else?
Guido already has: the typing module and its namespace along with the @no_type_hints decorator. Practicality beats Purity in this case and so adding any unnecessary overhead in the specification of the type hints is not going to fly. And your worry about all needing to flag non-type hints for annotations really only comes into play if the tool consuming them errors out or something when it comes across them. If it plays it safe and chooses unrecognized type hints as Any then any alternative use of annotations will just be ignored. I realize you don't like the loss in flexibility, but it is just a fact that function annotations are going to de-facto become type hint annotations in Python's future. They are the best use for annotations that we have come up with as a community and making the barrier to their use as low as possible puts it in the best interest of everyone to tighten the expectation of what annotations represent.