Re: Python Sanity Proposal: Type Hinting Solution

2015-01-26 Thread Marco Buttu
On 24/01/2015 15:09, Mario Figueiredo wrote: def myfunction(arg1, arg2): Normal docstring. @typehint: (str, int) - bool return True One of the problems with this is that it put the information about parameters far away from the parameter list itself. Then move it to the

Re: Python Sanity Proposal: Type Hinting Solution

2015-01-24 Thread Fetchinson .
On 1/24/15, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: Fetchinson . wrote: On 1/23/15, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: [...] Cobra is especially close to Python-like syntax, and supports unit tests as well: def sqroot(i as int) as float

Re: Python Sanity Proposal: Type Hinting Solution

2015-01-24 Thread Chris Angelico
On Sun, Jan 25, 2015 at 4:37 AM, Paul Rubin no.email@nospam.invalid wrote: Steven D'Aprano steve+comp.lang.pyt...@pearwood.info writes: versus any other decorator, but the STRING: @typehint(...) being used where a decorator would normally be expected. I didn't catch that either. I think if

Re: Python Sanity Proposal: Type Hinting Solution

2015-01-24 Thread Paul Rubin
Steven D'Aprano steve+comp.lang.pyt...@pearwood.info writes: versus any other decorator, but the STRING: @typehint(...) being used where a decorator would normally be expected. I didn't catch that either. I think if hints are to go in decorators, then it's best to extend the decorator

Re: Python Sanity Proposal: Type Hinting Solution

2015-01-24 Thread Rick Johnson
On Saturday, January 24, 2015 at 7:30:02 AM UTC-6, Steven D'Aprano wrote: [...] It requires extra complexity to the parser, so that decorators may be separated from the function by a hint: @decorate @typehint: (str, int) - bool def myfunction(arg1, arg2): No doubt some people will get

Re: Python Sanity Proposal: Type Hinting Solution

2015-01-24 Thread Steven D'Aprano
Rick Johnson wrote: On Saturday, January 24, 2015 at 7:30:02 AM UTC-6, Steven D'Aprano wrote: [...] It requires extra complexity to the parser, so that decorators may be separated from the function by a hint: @decorate @typehint: (str, int) - bool def myfunction(arg1, arg2): No doubt

Re: Python Sanity Proposal: Type Hinting Solution

2015-01-24 Thread Mark Lawrence
On 24/01/2015 17:26, Steven D'Aprano wrote: Rick Johnson wrote: On Saturday, January 24, 2015 at 7:30:02 AM UTC-6, Steven D'Aprano wrote: [...] It requires extra complexity to the parser, so that decorators may be separated from the function by a hint: @decorate @typehint: (str, int) - bool

Re: Python Sanity Proposal: Type Hinting Solution

2015-01-24 Thread Christian Gollwitzer
Am 23.01.15 um 20:23 schrieb Rick Johnson: On Thursday, January 22, 2015 at 9:22:40 PM UTC-6, Terry Reedy wrote: that it is already an option in mypy and is part of the new type-hint proposal. An *OPTION*? If it is not mandatory then why bother? If authors have a choice between writing type

Re: Python Sanity Proposal: Type Hinting Solution

2015-01-24 Thread Steven D'Aprano
Mario Figueiredo wrote: In article 54c39e48$0$12996$c3e8da3$54964...@news.astraweb.com, steve+comp.lang.pyt...@pearwood.info says... I'm not sure if you're making a general observation or one which is specific to Python. Plenty of languages have static analysis as a language feature. Are

Re: Python Sanity Proposal: Type Hinting Solution

2015-01-24 Thread Marko Rauhamaa
Steven D'Aprano steve+comp.lang.pyt...@pearwood.info: Marko Rauhamaa wrote: def weekday(day): assert isinstance(day, int) and 0 = day = 6 ... [...] Requiring the type-checker to parse and understand arbitrarily complex assertions would require the type-checker to be as

Re: Python Sanity Proposal: Type Hinting Solution

2015-01-24 Thread Tim Chase
On 2015-01-24 17:21, Steven D'Aprano wrote: # Cobra def sqroot(i as int) as float # Python def sqroot(i:int)-float: Cobra's use of as clashes with Python. In Python, as is used for name-binding: import module as name with open('file') as f except Exception as e but apart from

Re: Python Sanity Proposal: Type Hinting Solution

2015-01-24 Thread Steven D'Aprano
Tim Chase wrote: On 2015-01-24 17:21, Steven D'Aprano wrote: # Cobra def sqroot(i as int) as float # Python def sqroot(i:int)-float: Cobra's use of as clashes with Python. In Python, as is used for name-binding: import module as name with open('file') as f except Exception as e

Re: Python Sanity Proposal: Type Hinting Solution

2015-01-24 Thread Roy Smith
In article 54c3a0c1$0$13013$c3e8da3$54964...@news.astraweb.com, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: Tim Chase wrote: On 2015-01-24 17:21, Steven D'Aprano wrote: # Cobra def sqroot(i as int) as float # Python def sqroot(i:int)-float: Cobra's use of

Re: Python Sanity Proposal: Type Hinting Solution

2015-01-24 Thread Mario Figueiredo
In article mpg.2f2dc5f7f281009b989...@nntp.aioe.org, mar...@gmail.com says... In article 54c39e48$0$12996$c3e8da3$54964...@news.astraweb.com, steve+comp.lang.pyt...@pearwood.info says... def myfunction(arg1, arg2): Normal docstring. @typehint: (str, int) - bool

Re: Python Sanity Proposal: Type Hinting Solution

2015-01-24 Thread Steven D'Aprano
Mario Figueiredo wrote: In article 4b3b498a-c9b0-443d-8514-87ccd8e98...@googlegroups.com, rantingrickjohn...@gmail.com says... (Example modified for PEP8 compliance ;-) @typehint(arg1:str, arg2:int, returns:bool) def myfunction(arg1, arg2): return True Of

Re: Python Sanity Proposal: Type Hinting Solution

2015-01-24 Thread Mario Figueiredo
In article 54c39e48$0$12996$c3e8da3$54964...@news.astraweb.com, steve+comp.lang.pyt...@pearwood.info says... I'm not sure if you're making a general observation or one which is specific to Python. Plenty of languages have static analysis as a language feature. Are you arguing they are wrong

Re: Python Sanity Proposal: Type Hinting Solution

2015-01-23 Thread Chris Angelico
On Sat, Jan 24, 2015 at 12:23 AM, Fetchinson . fetchin...@googlemail.com wrote: In any case, I'm pretty sure it was said before, but I can't really find it anywhere, can someone tell me what the rationale is for *function signature* type hinting? I totally get type hinting in general, but why

Re: Python Sanity Proposal: Type Hinting Solution

2015-01-23 Thread Rick Johnson
On Thursday, January 22, 2015 at 9:22:40 PM UTC-6, Terry Reedy wrote: On 1/22/2015 8:15 PM, Rick Johnson wrote: Okay, i have found a solution to the type hinting problem that will appease both sides. On one side we have those who are proposing type hinting annotations within function

Re: Python Sanity Proposal: Type Hinting Solution

2015-01-23 Thread Rick Johnson
On Thursday, January 22, 2015 at 9:24:01 PM UTC-6, Rustom Mody wrote: Simplistic Example Code utilizing two files: [...snip code example...] 1. Allow

Re: Python Sanity Proposal: Type Hinting Solution

2015-01-23 Thread Rick Johnson
On Friday, January 23, 2015 at 7:23:34 AM UTC-6, Fetchinson . wrote: I really like the idea that in python I don't have lots of choices in many areas, certain things are dictated. The big advantage is that when I read other people's code I know what to expect so me being restricted is a small

Re: Python Sanity Proposal: Type Hinting Solution

2015-01-23 Thread Chris Angelico
On Sat, Jan 24, 2015 at 6:48 AM, Rick Johnson rantingrickjohn...@gmail.com wrote: On Thursday, January 22, 2015 at 10:04:29 PM UTC-6, Chris Angelico wrote: It's worth pointing out, too, that the idea isn't panaceaic - it's just another tool in the box. Any time you break related things into

Re: Python Sanity Proposal: Type Hinting Solution

2015-01-23 Thread Rick Johnson
On Thursday, January 22, 2015 at 10:04:29 PM UTC-6, Chris Angelico wrote: It's worth pointing out, too, that the idea isn't panaceaic - it's just another tool in the box. Any time you break related things into separate places, especially separate files, the tendency for them to get out of

Re: Python Sanity Proposal: Type Hinting Solution

2015-01-23 Thread Fetchinson .
On 1/23/15, Chris Angelico ros...@gmail.com wrote: On Sat, Jan 24, 2015 at 12:23 AM, Fetchinson . fetchin...@googlemail.com wrote: In any case, I'm pretty sure it was said before, but I can't really find it anywhere, can someone tell me what the rationale is for *function signature* type

Re: Python Sanity Proposal: Type Hinting Solution

2015-01-23 Thread sohcahtoa82
On Friday, January 23, 2015 at 2:46:01 PM UTC-8, Mario Figueiredo wrote: In article mpg.2f2cecb4624e49c4989...@nntp.aioe.org, mar...@gmail.com says... So I'd rather see: def myfunction(arg1, arg2): Normal docstring. @typehint: (str, int) - bool

Re: Python Sanity Proposal: Type Hinting Solution

2015-01-23 Thread Mario Figueiredo
In article c1d9c448-31b0-4bbc-8c6f-5194678a6...@googlegroups.com, sohcahto...@gmail.com says... def myfunction(arg1, arg2): Normal docstring... @typehint: (str, int) - bool return True I really like that implementation. Its

Re: Python Sanity Proposal: Type Hinting Solution

2015-01-23 Thread Rick Johnson
On Friday, January 23, 2015 at 1:59:38 PM UTC-6, Chris Angelico wrote: On Sat, Jan 24, 2015 at 6:48 AM, Sir Rick Johnson wrote: On Thursday, January 22, 2015 at 10:04:29 PM UTC-6, Chris Angelico wrote: It's worth pointing out, too, that the idea isn't panaceaic - it's just another tool in

Re: Python Sanity Proposal: Type Hinting Solution

2015-01-23 Thread Rick Johnson
On Friday, January 23, 2015 at 3:13:12 PM UTC-6, Mario Figueiredo wrote: In article 12d74fb6-f7d7-4ff0-88d3-6076a5dc7...@googlegroups.com, Sir Richard Johnson The First says... Injecting polarity into debates is dangerous, because, then we get off into the emotional weeds and a solution

Re: Python Sanity Proposal: Type Hinting Solution

2015-01-23 Thread Mario Figueiredo
In article 4b3b498a-c9b0-443d-8514-87ccd8e98...@googlegroups.com, rantingrickjohn...@gmail.com says... (Example modified for PEP8 compliance ;-) @typehint(arg1:str, arg2:int, returns:bool) def myfunction(arg1, arg2): return True Of course @typehint could

Re: Python Sanity Proposal: Type Hinting Solution

2015-01-23 Thread Mario Figueiredo
In article 5afad59b-5e8c-4821-85cf-9e971c8c7...@googlegroups.com, rantingrickjohn...@gmail.com says... On Thursday, January 22, 2015 at 10:04:29 PM UTC-6, Chris Angelico wrote: It's worth pointing out, too, that the idea isn't panaceaic - it's just another tool in the box. Any time you

Re: Python Sanity Proposal: Type Hinting Solution

2015-01-23 Thread Mario Figueiredo
In article mpg.2f2cecb4624e49c4989...@nntp.aioe.org, mar...@gmail.com says... So I'd rather see: def myfunction(arg1, arg2): Normal docstring. @typehint: (str, int) - bool return True Actually that is idiotic. Much better is: def

Re: Python Sanity Proposal: Type Hinting Solution

2015-01-23 Thread Rick Johnson
On Friday, January 23, 2015 at 3:02:57 PM UTC-6, Mario Figueiredo wrote: In any case, I agree entirely with you that type annotation is one ugly syntax to a programming language that is touted everywhere as being simple and easy to read. I would say that the mistake started 5 years ago, and

Re: Python Sanity Proposal: Type Hinting Solution

2015-01-23 Thread Mario Figueiredo
In article 12d74fb6-f7d7-4ff0-88d3-6076a5dc7...@googlegroups.com, rantingrickjohn...@gmail.com says... Injecting polarity into debates is dangerous, because, then we get off into the emotional weeds and a solution may never be found -- just observe the polarization of American politics if

Re: Python Sanity Proposal: Type Hinting Solution

2015-01-23 Thread Marko Rauhamaa
Mario Figueiredo mar...@gmail.com: Much better is: def myfunction(arg1, arg2): Normal docstring... @typehint: (str, int) - bool return True I seem to remember an idea floated on the Scheme mailing list of using assertions for such a purpose:

Re: Python Sanity Proposal: Type Hinting Solution

2015-01-23 Thread Rick Johnson
On Friday, January 23, 2015 at 4:42:51 PM UTC-6, Mario Figueiredo wrote: I'd rather it'd be a docstring parameter. - Decorators are transformation tools. Which type hints are not. Valid point. - keywords should be few and used only for language features. Static analysis isn't and should

Re: Python Sanity Proposal: Type Hinting Solution

2015-01-23 Thread Chris Angelico
On Sat, Jan 24, 2015 at 5:36 PM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: Chris Angelico wrote: But having just watched a PyCon talk about PyPy and RPython and type inference Ooh! Got a link? Well, it's not primarily about type inference, but the matter is mentioned. It's

Re: Python Sanity Proposal: Type Hinting Solution

2015-01-23 Thread Steven D'Aprano
Marko Rauhamaa wrote: I seem to remember an idea floated on the Scheme mailing list of using assertions for such a purpose: def myfunction(arg1, arg2): assert isinstance(arg1, str) and isinstance(arg2, int) return True The advantage is that the assertions can be as

Re: Python Sanity Proposal: Type Hinting Solution

2015-01-23 Thread Chris Angelico
On Sat, Jan 24, 2015 at 4:29 PM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: Sufficiently clever type-checkers may use assertions to infer types, but requiring this is a non-starter. Or they could use the isinstance checks themselves to infer types. def func(arg): if not

Re: Python Sanity Proposal: Type Hinting Solution

2015-01-23 Thread Steven D'Aprano
Chris Angelico wrote: But having just watched a PyCon talk about PyPy and RPython and type inference Ooh! Got a link? -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Python Sanity Proposal: Type Hinting Solution

2015-01-23 Thread Steven D'Aprano
Fetchinson . wrote: On 1/23/15, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: [...] Cobra is especially close to Python-like syntax, and supports unit tests as well: def sqroot(i as int) as float require i 0 ensure result 0

Re: Python Sanity Proposal: Type Hinting Solution

2015-01-23 Thread Fetchinson .
On 1/23/15, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: Terry Reedy wrote: On 1/22/2015 10:59 PM, Chris Angelico wrote: On Fri, Jan 23, 2015 at 2:22 PM, Terry Reedy tjre...@udel.edu wrote: This idea is so brilliant that it is already an option in mypy and is part of the new

Re: Python Sanity Proposal: Type Hinting Solution

2015-01-22 Thread Terry Reedy
On 1/22/2015 8:15 PM, Rick Johnson wrote: Okay, i have found a solution to the type hinting problem that will appease both sides. On one side we have those who are proposing type hinting annotations within function sigs, and on the other side, we have those who oppose the implementation of type

Re: Python Sanity Proposal: Type Hinting Solution

2015-01-22 Thread MRAB
On 2015-01-23 01:15, Rick Johnson wrote: Note: This is the closest you're going to get to a PEP from me! Okay, i have found a solution to the type hinting problem that will appease both sides. On one side we have those who are proposing type hinting annotations within function sigs, and on the

Re: Python Sanity Proposal: Type Hinting Solution

2015-01-22 Thread Chris Angelico
On Fri, Jan 23, 2015 at 2:22 PM, Terry Reedy tjre...@udel.edu wrote: This idea is so brilliant that it is already an option in mypy and is part of the new type-hint proposal. The separate type-hint files are called 'stub files'. It's worth pointing out, too, that the idea isn't panaceaic -

Re: Python Sanity Proposal: Type Hinting Solution

2015-01-22 Thread Rustom Mody
On Friday, January 23, 2015 at 6:45:39 AM UTC+5:30, Rick Johnson wrote: Note: This is the closest you're going to get to a PEP from me! Okay, i have found a solution to the type hinting problem that will appease both sides. On one side we have those who are proposing type hinting

Re: Python Sanity Proposal: Type Hinting Solution

2015-01-22 Thread Terry Reedy
On 1/22/2015 10:59 PM, Chris Angelico wrote: On Fri, Jan 23, 2015 at 2:22 PM, Terry Reedy tjre...@udel.edu wrote: This idea is so brilliant that it is already an option in mypy and is part of the new type-hint proposal. The separate type-hint files are called 'stub files'. It's worth

Python Sanity Proposal: Type Hinting Solution

2015-01-22 Thread Rick Johnson
Note: This is the closest you're going to get to a PEP from me! Okay, i have found a solution to the type hinting problem that will appease both sides. On one side we have those who are proposing type hinting annotations within function sigs, and on the other side, we have those who oppose

Re: Python Sanity Proposal: Type Hinting Solution

2015-01-22 Thread Chris Angelico
On Fri, Jan 23, 2015 at 4:03 PM, Terry Reedy tjre...@udel.edu wrote: On 1/22/2015 10:59 PM, Chris Angelico wrote: On Fri, Jan 23, 2015 at 2:22 PM, Terry Reedy tjre...@udel.edu wrote: This idea is so brilliant that it is already an option in mypy and is part of the new type-hint proposal.

Re: Python Sanity Proposal: Type Hinting Solution

2015-01-22 Thread Steven D'Aprano
Terry Reedy wrote: On 1/22/2015 10:59 PM, Chris Angelico wrote: On Fri, Jan 23, 2015 at 2:22 PM, Terry Reedy tjre...@udel.edu wrote: This idea is so brilliant that it is already an option in mypy and is part of the new type-hint proposal. The separate type-hint files are called 'stub