[Python-Dev] Re: Function suggestion: itertools.one()

2020-07-28 Thread Noam Yorav-Raphael
I'm sorry, I don't think I got that. I don't find a mailing list called
itertools-ideas. Do you mean this should go to python-ideas? If so, I'm
sorry for bothering python-dev, and I'll move this to python-ideas.

I just read "The python-ideas list is for discussing more speculative
design ideas" (https://www.python.org/community/lists/) as meaning
discussing ideas for significant design changes, and not for adding a small
function.

Thanks,
Noam

>
___
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/67MPZN4ZB7JXR47HGJWW66TIJCOQ4AEZ/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-Dev] Re: PEP 626: Precise line numbers for debugging and other tools.

2020-07-28 Thread Steve Dower

On 25Jul2020 2014, Jim J. Jewett wrote:

But it sounds as though you are saying the benefit is irrelevant; it is just 
inherently too expensive to ask programs that are already dealing with 
internals and trying to optimize performance to make a mechanical change from:
 code.magic_attrname
to:
 magicdict[code]

What have I missed?


You've missed that debugging and profiling tools that operate purely on 
native memory can't execute Python code, so the "magic" has to be easily 
representable in C such that it can be copied into whichever language is 
being used (whether it's C, C++, C#, Rust, or something else).


Cheers,
Steve
___
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/PE44CTX6NG6KOUPIJUFRXJHNFSFMN2TK/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-Dev] Re: Function suggestion: itertools.one()

2020-07-28 Thread Brett Cannon
For ideas like this it is best to discuss them on python-ideas.

I'll also mention that this idea has been brought up at least twice before:
search for threads about itertools and single() or first() (if I remember
correctly).

On Mon, Jul 27, 2020 at 12:07 PM Noam Yorav-Raphael 
wrote:

> Hi,
>
> There's a simple function that I use many times, and I think may be a good
> fit to be added to itertools. A function that gets an iterator, and if it
> has exactly one element returns it, and otherwise raises an exception. This
> is very useful for cases where I do some sort of query that I expect to get
> exactly one result, and I want an exception to be raised if I'm wrong. For
> example:
>
> jack = one(p for p in people if p.id == '1234')
>
> sqlalchemy already has such a function for queries:
> https://docs.sqlalchemy.org/en/13/orm/query.html#sqlalchemy.orm.query.Query.one
>
> This is my implementation:
>
> def one(iterable):
> it = iter(iterable)
> try:
> r = next(it)
> except StopIteration:
> raise ValueError("Iterator is empty")
> try:
> next(it)
> except StopIteration:
> return r
> else:
> raise ValueError("Iterator has more than one item")
>
> What do you think?
>
> Thanks,
> Noam
> ___
> Python-Dev mailing list -- python-dev@python.org
> To unsubscribe send an email to python-dev-le...@python.org
> https://mail.python.org/mailman3/lists/python-dev.python.org/
> Message archived at
> https://mail.python.org/archives/list/python-dev@python.org/message/D52MPKLIN4VEXBOCKVMTWAK66MAOEINY/
> Code of Conduct: http://python.org/psf/codeofconduct/
>
___
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/RO5PFRG4PCHFQGQPEJIXP5TGUF3KSZYO/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-Dev] Re: Function suggestion: itertools.one()

2020-07-28 Thread Joao S. O. Bueno
On Tue, 28 Jul 2020 at 15:16, Brett Cannon  wrote:

> For ideas like this it is best to discuss them on python-ideas.
>
> I'll also mention that this idea has been brought up at least twice
> before: search for threads about itertools and single() or first() (if I
> remember correctly).
>
I think "first" even passed "general approval'   last time around (about 1
month ago) -  but I can't recall if someone
took the responsibility of carrying that forward.

>
> On Mon, Jul 27, 2020 at 12:07 PM Noam Yorav-Raphael 
> wrote:
>
>> Hi,
>>
>> There's a simple function that I use many times, and I think may be a
>> good fit to be added to itertools. A function that gets an iterator, and if
>> it has exactly one element returns it, and otherwise raises an exception.
>> This is very useful for cases where I do some sort of query that I expect
>> to get exactly one result, and I want an exception to be raised if I'm
>> wrong. For example:
>>
>> jack = one(p for p in people if p.id == '1234')
>>
>> sqlalchemy already has such a function for queries:
>> https://docs.sqlalchemy.org/en/13/orm/query.html#sqlalchemy.orm.query.Query.one
>>
>> This is my implementation:
>>
>> def one(iterable):
>> it = iter(iterable)
>> try:
>> r = next(it)
>> except StopIteration:
>> raise ValueError("Iterator is empty")
>> try:
>> next(it)
>> except StopIteration:
>> return r
>> else:
>> raise ValueError("Iterator has more than one item")
>>
>> What do you think?
>>
>> Thanks,
>> Noam
>> ___
>> Python-Dev mailing list -- python-dev@python.org
>> To unsubscribe send an email to python-dev-le...@python.org
>> https://mail.python.org/mailman3/lists/python-dev.python.org/
>> Message archived at
>> https://mail.python.org/archives/list/python-dev@python.org/message/D52MPKLIN4VEXBOCKVMTWAK66MAOEINY/
>> Code of Conduct: http://python.org/psf/codeofconduct/
>>
> ___
> Python-Dev mailing list -- python-dev@python.org
> To unsubscribe send an email to python-dev-le...@python.org
> https://mail.python.org/mailman3/lists/python-dev.python.org/
> Message archived at
> https://mail.python.org/archives/list/python-dev@python.org/message/RO5PFRG4PCHFQGQPEJIXP5TGUF3KSZYO/
> Code of Conduct: http://python.org/psf/codeofconduct/
>
___
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/257F5YVGORDSDKMTGGX7FAQKHSNHA32I/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-Dev] Re: Function suggestion: itertools.one()

2020-07-28 Thread Noam Yorav-Raphael
Thanks! I opened a new thread in python-ideas, here:
https://mail.python.org/archives/list/python-id...@python.org/thread/6OLEL4XTUWXRI7ENODKEDOYFBRVDYKI7/

The "first" thread was very long, and was focused on a
different function, first(). Perhaps a new thread, focused on one simple
function in itertools, can reach a conclusion more easily.

Thanks,
Noam
___
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/NK2ERT4Z3T2LLSMEHTAOMYJBLIDY7FTV/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-Dev] Re: PEP 626: Precise line numbers for debugging and other tools.

2020-07-28 Thread Jim J. Jewett
ah... we may have been talking past each other.

Steve Dower wrote:
> On 25Jul2020 2014, Jim J. Jewett wrote:
> > But it sounds as though you are saying the benefit 

[of storing the line numbers in an external table, I thought,
but perhaps Pablo Galindo Salgado and yourself were 
talking only of the switch from an lnotab string to an opaque
co_linetable?]

> > is irrelevant; it is just inherently too expensive to ask programs that are 
> > already dealing
> > with internals and trying to optimize performance to make a mechanical 
> > change from:
> >  code.magic_attrname
> > to:
> >  magicdict[code]
> > What have I missed?

> You've missed that debugging and profiling tools that operate purely on 
> native memory can't execute Python code, so the "magic" has to be easily 
> representable in C such that it can be copied into whichever language is 
> being used (whether it's C, C++, C#, Rust, or something else).

Unless you really were talking only of the switch to co_linetable, I'm still 
missing the problem.  To me, it still looks like a call to:

PyAPI_FUNC(PyObject *) PyObject_GetAttrString(PyObject *, const char *);

with the code object being stepped through and "co_lnotab" 
would be replaced by:

PyAPI_FUNC(PyObject *) PyDict_GetItem(PyObject *mp, PyObject *key);

using that same code object as the key, but getting the dict from 
some well-known (yet-to-be-defined) location, such as sys.code_to_lnotab.

Mark Shannon and Carl Shapiro had seemed to object to the PEP because
the new structure would make the code object longer, and making it smaller
by a string does seem likely to be good.  But if your real objections are to
just to replacing the lnotab format with something that needs to be 
executed, then I apologize for misunderstanding.

-jJ
___
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/WUEFHFTPVTOPA3EFHACDECT3ZPLGGTFJ/
Code of Conduct: http://python.org/psf/codeofconduct/