Re: [Python-ideas] Why is design-by-contracts not widely adopted?

2018-10-07 Thread Chris Angelico
On Mon, Oct 8, 2018 at 4:26 PM Marko Ristin-Kaufmann wrote: >> Not true for good docstrings. We very seldom change the essential >> meaning of public functions. > > In my team, we have a stale docstring once every two weeks or even more > often. If it weren't for doctests and contracts, I could

Re: [Python-ideas] Why is design-by-contracts not widely adopted?

2018-10-07 Thread Marko Ristin-Kaufmann
Hi Terry, I would encourage you to read all the messages on the thread. The points you raised were actually already discussed: * Using formal contracts in the code does not imply that you must specify *all* the contracts; you specify what you consider meaningful. * Distinction of result/process

Re: [Python-ideas] Dynamic getting of __doc__ of a function

2018-10-07 Thread Marko Ristin-Kaufmann
Hi Steve, > > * built-in class function ignoring the property getter (some_func.__doc__ > > set to a property returns the property instead of invoking the getter) > > Not just functions, it is all instances. Properties are only invoked if > they are on the class object, not the instance. > I

Re: [Python-ideas] Support parsing stream with `re`

2018-10-07 Thread Nathaniel Smith
On Sun, Oct 7, 2018 at 5:54 PM, Nathaniel Smith wrote: > Are you imagining something roughly like this? (Ignoring chunk > boundary handling for the moment.) > > def find_double_line_end(buf): > start = 0 > while True: > next_idx = buf.index(b"\n", start) > if buf[next_idx

Re: [Python-ideas] Support parsing stream with `re`

2018-10-07 Thread Nathaniel Smith
On Sun, Oct 7, 2018 at 5:09 PM, Terry Reedy wrote: > On 10/6/2018 5:00 PM, Nathaniel Smith wrote: >> >> On Sat, Oct 6, 2018 at 12:22 AM, Ram Rachum wrote: >>> >>> I'd like to use the re module to parse a long text file, 1GB in size. I >>> wish >>> that the re module could parse a stream, so I

Re: [Python-ideas] Support parsing stream with `re`

2018-10-07 Thread Terry Reedy
On 10/7/2018 12:32 AM, Ram Rachum wrote: Does that mean I'll have to write that character-by-character algorithm? I would not be surprised if you could make use of str.index, which scans at C speed. See my answer to Nathaniel. -- Terry Jan Reedy

Re: [Python-ideas] Support parsing stream with `re`

2018-10-07 Thread Terry Reedy
On 10/6/2018 5:00 PM, Nathaniel Smith wrote: On Sat, Oct 6, 2018 at 12:22 AM, Ram Rachum wrote: I'd like to use the re module to parse a long text file, 1GB in size. I wish that the re module could parse a stream, so I wouldn't have to load the whole thing into memory. I'd like to iterate over

Re: [Python-ideas] Dynamic getting of __doc__ of a function

2018-10-07 Thread Steven D'Aprano
On Sun, Oct 07, 2018 at 06:17:47PM +0200, Marko Ristin-Kaufmann wrote: > Hi, > @Jonathan: thanks! I'll have a look at your links. > > So there are actually two issues if I understand correctly: > * help() ignoring the property getter when invoked on an instance Not just the property getter, but

Re: [Python-ideas] Support parsing stream with `re`

2018-10-07 Thread Greg Ewing
Jonathan Fine wrote: Provided mmap releases memory when possible, It will. The virtual memory system will read pages from the file into RAM when needed, and re-use those RAM pages for other purposes when needed. It should be pretty much the most efficient solution possible. -- Greg

Re: [Python-ideas] Better error messages for missing optional stdlib packages

2018-10-07 Thread Terry Reedy
On 10/3/2018 4:29 PM, Marcus Harnisch wrote: When trying to import lzma on one of my machines, I was suprised to get a normal import error like for any other module. What was the traceback and message? Did you get an import error for one of the three imports in lzma.py. I don't know why you

Re: [Python-ideas] Simplicity of C (was why is design-by-contracts not widely)

2018-10-07 Thread Terry Reedy
On 9/30/2018 2:19 AM, Marko Ristin-Kaufmann wrote: The library name will also need to change. When I started developing it, I was not aware of Java icontract library. It will be probably renamed to "pcontract" or any other suggested better name :) 'icontract' immediatly looks to me like

Re: [Python-ideas] add a time decorator to timeit.py

2018-10-07 Thread Guido van Rossum
So someone ought to submit a PR that adds (brief) documentation for this, with reference to this thread. On Sun, Oct 7, 2018 at 12:50 PM Jonathan Fine wrote: > On 7 Oct 2018 20:39, "Michael Selik" wrote: > > Isn't there some rule about noticing an undocumented feature, like, > whoever pours

Re: [Python-ideas] Why is design-by-contracts not widely adopted?

2018-10-07 Thread Terry Reedy
On 9/24/2018 3:46 AM, Marko Ristin-Kaufmann wrote: I am responding to your request "Please do point me to what is not obvious to you". I think some of your claims are not only not obvious, but are wrong. I have read some (probably less than half) of the responses and avoid saying what I

Re: [Python-ideas] add a time decorator to timeit.py

2018-10-07 Thread Jonathan Fine
On 7 Oct 2018 20:39, "Michael Selik" wrote: Isn't there some rule about noticing an undocumented feature, like, whoever pours the last cup of coffee needs to brew a fresh pot? :-) Most of the credit belongs, I think, to the original poster. His statement, that Python wasn't very Pythonic here,

Re: [Python-ideas] add a time decorator to timeit.py

2018-10-07 Thread Jonathan Fine
Summary: It's an undocumented feature, not an implementation detail. I wrote: > And if you're a software historian, now perhaps look at > https://github.com/python/cpython/commits/3.7/Lib/timeit.py Well, I've bitten my own bait, and have found it. See

Re: [Python-ideas] Support parsing stream with `re`

2018-10-07 Thread Jonathan Fine
Anders wrote > An mmap object is one of the things you can make a memoryview of, > although looking again, it seems you don't even need to, you can > just re.search the mmap object directly. > > re.search'ing the mmap object means the operating system takes care of > the streaming for you,

Re: [Python-ideas] Support parsing stream with `re`

2018-10-07 Thread 2015
On 18-10-07 16.15, Ram Rachum wrote: > I tested it now and indeed bytes patterns work on memoryview objects. > But how do I use this to scan for patterns through a stream without > loading it to memory? An mmap object is one of the things you can make a memoryview of, although looking again, it

Re: [Python-ideas] Dynamic getting of __doc__ of a function

2018-10-07 Thread Marko Ristin-Kaufmann
Hi, @Jonathan: thanks! I'll have a look at your links. So there are actually two issues if I understand correctly: * help() ignoring the property getter when invoked on an instance * built-in class function ignoring the property getter (some_func.__doc__ set to a property returns the property

Re: [Python-ideas] add a time decorator to timeit.py

2018-10-07 Thread Jonathan Fine
Summary: Python's timeit.timeit() has an undocumented feature / implementation detail that gives much of what the original poster has asked for. Perhaps revising the docs will solve the problem. This thread has prompted me to look at timeit again. Usually, I look at the command line help first.

Re: [Python-ideas] add a time decorator to timeit.py

2018-10-07 Thread Amjad Ben Hedhili
@Steven D'Aprano , I know you didn't ask for the implementation, but it does supports the idea and it contains comments describing how it's used. @Chris Angelico, I don't know if it needs to be further customizable (apart from a repeat

Re: [Python-ideas] Dynamic getting of __doc__ of a function

2018-10-07 Thread Jonathan Fine
Hi Marko You wrote: > I just couldn't figure out how to make the __doc__ attribute of a function a > getter. Is this a bug or am I making a mistake? If it's my mistake, is there > any other way how to dynamically __doc__ a function or am I forced to set > __doc__ of a function at the

Re: [Python-ideas] Dynamic getting of __doc__ of a function

2018-10-07 Thread Chris Angelico
On Mon, Oct 8, 2018 at 2:14 AM Steven D'Aprano wrote: > That might work for Marko's use-case, but the problem is more general > and I'd like to consider the broader picture. Currently instance __doc__ > attributes are sometimes ignored by help(). Given these: > > py> class X: > ... pass > ...

Re: [Python-ideas] Dynamic getting of __doc__ of a function

2018-10-07 Thread Steven D'Aprano
On Mon, Oct 08, 2018 at 01:45:01AM +1100, Chris Angelico wrote: > On Mon, Oct 8, 2018 at 1:41 AM Marko Ristin-Kaufmann > wrote: > > (If you wonder about the use case: I'd like to dynamically generate the > > docstrings when functions are decorated with contracts from icontract > > library.

Re: [Python-ideas] Dynamic getting of __doc__ of a function

2018-10-07 Thread Chris Angelico
On Mon, Oct 8, 2018 at 1:56 AM Marko Ristin-Kaufmann wrote: > > Hi Crhis, > >> Have you tried just generating the docstrings at decoration time and >> applying them? By the sound of it, they won't change after that, and >> the only reason to run it later is performance... but have you >> actually

Re: [Python-ideas] Dynamic getting of __doc__ of a function

2018-10-07 Thread Marko Ristin-Kaufmann
Hi Crhis, Have you tried just generating the docstrings at decoration time and > applying them? By the sound of it, they won't change after that, and > the only reason to run it later is performance... but have you > actually measured a performance hit resulting from that? I did. On my laptop

Re: [Python-ideas] Dynamic getting of __doc__ of a function

2018-10-07 Thread Chris Angelico
On Mon, Oct 8, 2018 at 1:41 AM Marko Ristin-Kaufmann wrote: > (If you wonder about the use case: I'd like to dynamically generate the > docstrings when functions are decorated with contracts from icontract > library. Condition functions need to be parsed and re-formatted, so this is >

Re: [Python-ideas] Dynamic getting of __doc__ of a function

2018-10-07 Thread Marko Ristin-Kaufmann
Hi Steve, Here are a couple of code snippets. I hope it's not too verbose :) Setting property on the __doc__ works on the instance, but not on the class: class A: @property def __doc__(self): return "Works only on the instance" a = A() print('A.__doc__ is {}'.format(A.__doc__))

Re: [Python-ideas] Support parsing stream with `re`

2018-10-07 Thread Ram Rachum
I tested it now and indeed bytes patterns work on memoryview objects. But how do I use this to scan for patterns through a stream without loading it to memory? On Sun, Oct 7, 2018 at 4:24 PM <2...@jmunch.dk> wrote: > On 18-10-07 15.11, Ram Rachum wrote: > > > Unfortunately, it's not helpful. I

Re: [Python-ideas] Support parsing stream with `re`

2018-10-07 Thread 2015
On 18-10-07 15.11, Ram Rachum wrote: > Unfortunately, it's not helpful. I was developing a solution similar to yours before I came to the conclusion that a multilne regex would be more elegant. How about memory mapping your 1GB file? bytes patterns work on memoryviews. regards, Anders

Re: [Python-ideas] Support parsing stream with `re`

2018-10-07 Thread Ram Rachum
Hi Cameron, Thanks for putting in the time to study my problem and sketch a solution. Unfortunately, it's not helpful. I was developing a solution similar to yours before I came to the conclusion that a multilne regex would be more elegant. I find this algorithm to be quite complicated. It's

Re: [Python-ideas] add a time decorator to timeit.py

2018-10-07 Thread Chris Angelico
On Sun, Oct 7, 2018 at 11:34 PM Steven D'Aprano wrote: > Unfortunately, not every good idea can or will make it into the std lib. > Even if the idea is good, we might decide that it belongs as a third- > party library, or that the benefit is not enough to make up for the cost > in effort or

Re: [Python-ideas] add a time decorator to timeit.py

2018-10-07 Thread Steven D'Aprano
On Sun, Oct 07, 2018 at 11:43:40AM +, Amjad Ben Hedhili wrote: > this is my implementation: I didn't ask about the current implementation, as that might change. I asked about the interface: what it does, not how it does it. For the purposes of Python-Ideas, we want to discuss the feature,

Re: [Python-ideas] Debugging: some problems and possible solutions

2018-10-07 Thread Stephen J. Turnbull
Samuel Colvin writes: > Python definitely needs a dedicated debug print command. For *commands* (ie, a REPL), you have Pdb already. It's unlikely a *statement* would be accepted, given that print was demoted from a statement to a function. And it's not obvious why a "debug.print()" function

Re: [Python-ideas] Debugging: some problems and possible solutions

2018-10-07 Thread Stephen J. Turnbull
Jonathan Fine writes: > I'm thinking of providing a builtin debug() command "Command" doesn't make much sense in this context. I presume you mean "function". > that 'does the right thing' according to the context. And the > context would include the user's preferences. Which might be to use

Re: [Python-ideas] Support parsing stream with `re`

2018-10-07 Thread Nathaniel Smith
On Sat, Oct 6, 2018, 18:40 Steven D'Aprano wrote: > The message I take from this is: > > - regex engines certainly can be written to support streaming data; > - but few of them are; > - and it is exceedingly unlikely to be able to easily (or at all) > retro-fit that support to Python's

Re: [Python-ideas] add a time decorator to timeit.py

2018-10-07 Thread Amjad Ben Hedhili
this is my implementation: ``` units = {"auto": -1, "s": 1, "ms": 1e3, "μs": 1e6, "ns": 1e9} def timef(unit="auto", number=1, garcol=True, get_time=False): """A decorator to measure the execution time of a function Returns the return of the tested function if get_time is False or the

Re: [Python-ideas] add a time decorator to timeit.py

2018-10-07 Thread Steven D'Aprano
On Sun, Oct 07, 2018 at 10:16:08AM +, Amjad Ben Hedhili wrote: > I think that a time decorator will be a useful addition to the sandard > library, as i find the current way of measuring execution time a bit > tedious: > > timeit.timeit("fun_to_time(a, b)", setup="from __main__ import a,

[Python-ideas] add a time decorator to timeit.py

2018-10-07 Thread Amjad Ben Hedhili
I think that a time decorator will be a useful addition to the sandard library, as i find the current way of measuring execution time a bit tedious: timeit.timeit("fun_to_time(a, b)", setup="from __main__ import a, b", number=1) compared to: @timef def fun_to_time(a, b): ... or

Re: [Python-ideas] Dynamic getting of __doc__ of a function

2018-10-07 Thread Steven D'Aprano
On Sun, Oct 07, 2018 at 09:25:13AM +0200, Marko Ristin-Kaufmann wrote: > Hi, > I'm working on decorators that have a dynamic __doc__ property computed at > runtime and not at decoration time. You mean like this? py> class X: ... @property ... def __doc__(self): ... return "NOBODY

[Python-ideas] Dynamic getting of __doc__ of a function

2018-10-07 Thread Marko Ristin-Kaufmann
Hi, I'm working on decorators that have a dynamic __doc__ property computed at runtime and not at decoration time. The decorator must return the wrapper as a function and can not return a callable object with __call__ since the "self" argument would not be properly passed through the decorator.

Re: [Python-ideas] Support parsing stream with `re`

2018-10-07 Thread Cameron Simpson
On 07Oct2018 07:32, Ram Rachum wrote: On Sun, Oct 7, 2018 at 4:40 AM Steven D'Aprano wrote: I'm sure that Python will never be as efficient as C in that regard (although PyPy might argue the point) but is there something we can do to ameliorate this? If we could make char-by-char processing

Re: [Python-ideas] Support parsing stream with `re`

2018-10-07 Thread Cameron Simpson
On 07Oct2018 07:30, Ram Rachum wrote: I'm doing multi-color 3d-printing. The slicing software generates a GCode file, which is a text file of instructions for the printer, each command meaning something like "move the head to coordinates x,y,z while extruding plastic at a rate of w" and lots of