Re: [Python-ideas] Contracts in python -- a report & next steps

2018-10-25 Thread Stéfane Fermigier
A few thoughts: 1) Just as with with PEP 484, we could distinguish between contract specification and checking. To achieve some of the goals that you state, we need to standardise the way people would state contracts in their code (and provide a small implementation in the stdlib, similar to the

Re: [Python-ideas] Return for assignment blocks

2018-10-25 Thread Anders Hovmöller
> The point is not saving a line or typing, but saving a thought. Expressing > the intent of the factory function more clearly. Could you give some other usage examples? To me it seems like a nicer and less confusing way to create decorators is warranted but could then be more specialized

Re: [Python-ideas] Return for assignment blocks

2018-10-25 Thread Calvin Spealman
On Wed, Oct 24, 2018 at 4:41 PM Steven D'Aprano wrote: > On Wed, Oct 24, 2018 at 09:18:14AM -0400, Calvin Spealman wrote: > > I'd like to suggest what I think would be a simple addition to `def` and > > `class` blocks. I don't know if calling those "Assignment Blocks" is > > accurate, but I just

Re: [Python-ideas] Set starting point for itertools.product()

2018-10-25 Thread Steven D'Aprano
On Thu, Oct 25, 2018 at 02:31:05PM +0800, Ronie Martinez wrote: > def main(): > datetime_odometer = itertools.product( > range(2018, 10_000), # year > range(1, 13), # month > range(1, 31), # days > range(0, 24), # hours > range(0, 60), # minutes >

Re: [Python-ideas] Return for assignment blocks

2018-10-25 Thread Rhodri James
On 25/10/2018 02:15, Virendra Tripathi wrote: In addition to what GVR wrote, a generator function would have to have its own syntax - backward compatibility would be another issue. No it wouldn't. This is about returning the function/generator/class itself, not its results. I still don't

[Python-ideas] Problems (and solutions?) in writing decorators

2018-10-25 Thread Jonathan Fine
Was: Return for assignment blocks Anders Hovmöller wrote: > Personally I often just copy paste an existing decorator and then tweak it > instead of writing from scratch because it's too confusing and error prone to > do that. Thank you, Anders, for your honesty. I also find writing decorators

Re: [Python-ideas] Return for assignment blocks

2018-10-25 Thread Guido van Rossum
On Thu, Oct 25, 2018 at 7:41 AM Calvin Spealman wrote: > > On Thu, Oct 25, 2018 at 9:28 AM Anders Hovmöller > wrote: > >> [Calvin] >> > The point is not saving a line or typing, but saving a thought. >> Expressing the intent of the factory function more clearly. >> > [...] > You know what, I

Re: [Python-ideas] Return for assignment blocks

2018-10-25 Thread Greg Ewing
Calvin Spealman wrote: You know what, I /can't/ think of other good examples than slightly improved decorators. So, maybe its not that great an idea if it can't be applied to at least a few more use cases. The class version might be useful for things like namedtuple that dynamically create

Re: [Python-ideas] Problems (and solutions?) in writing decorators

2018-10-25 Thread Greg Ewing
Jonathan Fine wrote: I also find writing decorators a bit hard. It seems to be something I have to learn anew each time I do it. Particularly for the pattern @deco(arg1, arg2) def fn(arg3, arg4): > # function body Perhaps doing something with partial might help here. Anyone here

Re: [Python-ideas] Contracts in python -- a report & next steps

2018-10-25 Thread Marko Ristin-Kaufmann
Hi, Stephen J. Turnbull wrote: > You can't weaken the > contracts for iparent.recontract as far as I can see in a decorator- > based contract library Of course you can weaken the contracts for iparent.recontract with a decorator-based contract library. From my first message: > The features

Re: [Python-ideas] name2type mapping

2018-10-25 Thread Guido van Rossum
On Thu, Oct 25, 2018 at 1:35 PM Steven D'Aprano wrote: > On Thu, Oct 25, 2018 at 10:04:05PM +0200, Thomas Güttler Lists wrote: > > I created a first draft of the name2type mapping which was discussed > > here some days ago: > > Since this is not a language feature, please take the discussion to

Re: [Python-ideas] Return for assignment blocks

2018-10-25 Thread Calvin Spealman
On Thu, Oct 25, 2018 at 9:28 AM Anders Hovmöller wrote: > > > The point is not saving a line or typing, but saving a thought. > Expressing the intent of the factory function more clearly. > > Could you give some other usage examples? > > To me it seems like a nicer and less confusing way to

Re: [Python-ideas] name2type mapping

2018-10-25 Thread Steven D'Aprano
On Thu, Oct 25, 2018 at 10:04:05PM +0200, Thomas Güttler Lists wrote: > I created a first draft of the name2type mapping which was discussed > here some days ago: Since this is not a language feature, please take the discussion to a more appropriate forum such as this:

[Python-ideas] name2type mapping

2018-10-25 Thread Thomas Güttler Lists
I created a first draft of the name2type mapping which was discussed here some days ago: https://github.com/guettli/python-name2type-mapping/blob/master/README.rst Feedback is welcome. Regards,   Thomas Güttler -- Thomas Guettler http://www.thomas-guettler.de/ I am looking for feedback:

Re: [Python-ideas] Return for assignment blocks

2018-10-25 Thread Steven D'Aprano
On Thu, Oct 25, 2018 at 08:44:44AM -0400, Calvin Spealman wrote: > On Wed, Oct 24, 2018 at 4:41 PM Steven D'Aprano wrote: [...] > > I *think* you are proposing the following syntax. Am I right? > > > > > > return def (func): > > # body of func > > > > which is equivalent to: > > > > def func:

Re: [Python-ideas] Set starting point for itertools.product()

2018-10-25 Thread Serhiy Storchaka
25.10.18 09:31, Ronie Martinez пише: Here is an example: import itertools import time def main(): datetime_odometer = itertools.product( range(2018,10_000),# year range(1,13),# month range(1,31),# days range(0,24),# hours range(0,60),# minutes range(0,60)# seconds )

Re: [Python-ideas] Set starting point for itertools.product()

2018-10-25 Thread Ronie Martinez
Hi Serhiy, I missed the 31st on days range. Thanks for spotting it. I do verify if the datetime tuple is correct by passing them to datetime() and raising exception later on on the code (see https://github.com/Code-ReaQtor/DocCron/blob/1.0.0/doccron/job.py#L180) Datetime and timedeltas can solve

Re: [Python-ideas] Set starting point for itertools.product()

2018-10-25 Thread Ronie Martinez
Hi Serhiy, __setstate__() made it possible to specify the starting point. Using this method and combining it with binning (if the items does not have any pattern) worked well! Thanks for the suggestion. Cheers! Best Regards, Ronie On Fri, Oct 26, 2018 at 10:31 AM Ronie Martinez wrote: > Hi

Re: [Python-ideas] Contracts in python -- a report & next steps

2018-10-25 Thread Nathaniel Smith
On Thu, Oct 25, 2018, 14:44 Marko Ristin-Kaufmann wrote: > > Nathaniel Smith wrote: > >> In your position, I wouldn't be talking to the core devs; I'd be >> writing blog posts to proselytize the advantages of contracts, working >> with popular projects that are interested in adopting them,

Re: [Python-ideas] Set starting point for itertools.product()

2018-10-25 Thread Ronie Martinez
Hi Steve, I tried this when writing DocCron but it will not work correctly. Suppose we have minutes with range 0-59 and seconds with range 0-59 but starting at, say, 5: When the seconds value reaches 59, on the next iteration the minute value should