Re: [Python-Dev] Py_SIZE vs PyXXX_GET_SIZE

2017-03-20 Thread Victor Stinner
We may modify PyXXX_GET_SIZE() to add assert(PyXXX_Check()) to help to detect bugs and misuses of these macros in debug mode. The problem is that I expect a compilation error on PyXXX_GET_SIZE()=size. The new PyDict_GET_SIZE() macro has the assertion. Use Py_SIZE() to set the size. Victor Le 20

Re: [Python-Dev] Py_SIZE vs PyXXX_GET_SIZE

2017-03-20 Thread Benjamin Peterson
On Mon, Mar 20, 2017, at 13:18, Antoine Pitrou wrote: > On Mon, 20 Mar 2017 13:26:34 +0200 > Serhiy Storchaka wrote: > > What is the preferable way of getting the size of tuple, list, bytes, > > bytearray: Py_SIZE or PyTuple_GET_SIZE, PyList_GET_SIZE, > > PyBytes_GET_SIZE, PyByteArray_GET_SIZE

Re: [Python-Dev] PEP 544: Protocols

2017-03-20 Thread Ivan Levkivskyi
On 21 March 2017 at 00:23, Barry Warsaw wrote: > On Mar 20, 2017, at 01:00 PM, Ivan Levkivskyi wrote: > > [SNIP] > > IIUC, the Python 3 way to spell this is with a decorator. > Thanks, I will update this. > [SNIP] > (also, since this is Python 3, do you really need to inherit from object?) >

Re: [Python-Dev] PEP 544: Protocols

2017-03-20 Thread Barry Warsaw
On Mar 20, 2017, at 01:00 PM, Ivan Levkivskyi wrote: >from zope.interface import Interface, Attribute, implements > >class IEmployee(Interface): > >name = Attribute("Name of employee") > >def do(work): >"""Do some work""" > >class Employee(object): >

Re: [Python-Dev] PEP 544: Protocols

2017-03-20 Thread Ivan Levkivskyi
On 20 March 2017 at 22:11, Matthias Kramm wrote: > I'm a big fan of this. I really want structural subtyping for > http://github.com/google/pytype. > > I am glad you like it. > > On Mon, Mar 20, 2017 at 5:00 AM, Ivan Levkivskyi > wrote: > >> Explicitly declaring implementation >> -

Re: [Python-Dev] __del__ is not called after creating a new reference

2017-03-20 Thread Nathaniel Smith
On Mar 20, 2017 1:26 PM, "Antoine Pitrou" wrote: Hello Oleg, On Mon, 20 Mar 2017 18:28:29 +0100 Oleg Nesterov wrote: > I started to learn python a few days ago and I am trying to understand what > __del__() actually does. https://docs.python.org/3/ reference/datamodel.html > says: > > ob

Re: [Python-Dev] PEP 544: Protocols

2017-03-20 Thread Matthias Kramm via Python-Dev
I'm a big fan of this. I really want structural subtyping for http://github.com/google/pytype. On Mon, Mar 20, 2017 at 5:00 AM, Ivan Levkivskyi wrote: > Explicitly declaring implementation > --- > > To explicitly declare that a certain class implements the given p

Re: [Python-Dev] __del__ is not called after creating a new reference

2017-03-20 Thread MRAB
On 2017-03-20 20:23, Antoine Pitrou wrote: Hello Oleg, On Mon, 20 Mar 2017 18:28:29 +0100 Oleg Nesterov wrote: I started to learn python a few days ago and I am trying to understand what __del__() actually does. https://docs.python.org/3/reference/datamodel.html says: object.__del__(

Re: [Python-Dev] __del__ is not called after creating a new reference

2017-03-20 Thread Antoine Pitrou
Hello Oleg, On Mon, 20 Mar 2017 18:28:29 +0100 Oleg Nesterov wrote: > I started to learn python a few days ago and I am trying to understand what > __del__() actually does. https://docs.python.org/3/reference/datamodel.html > says: > > object.__del__(self) > ... > Note that it

Re: [Python-Dev] Py_SIZE vs PyXXX_GET_SIZE

2017-03-20 Thread Antoine Pitrou
On Mon, 20 Mar 2017 13:26:34 +0200 Serhiy Storchaka wrote: > What is the preferable way of getting the size of tuple, list, bytes, > bytearray: Py_SIZE or PyTuple_GET_SIZE, PyList_GET_SIZE, > PyBytes_GET_SIZE, PyByteArray_GET_SIZE? Are macros for concrete types > more preferable or they are out

Re: [Python-Dev] PEP 544: Protocols

2017-03-20 Thread Random832
On Mon, Mar 20, 2017, at 14:07, Brett Cannon wrote: > What is a "trivial body"? I don't know of any such definition anywhere in > Python so this is too loosely defined. You also don't say what happens if > the body isn't trivial. Are tools expected to raise an error? My assumption would be that a

Re: [Python-Dev] PEP 544: Protocols

2017-03-20 Thread Ivan Levkivskyi
On 20 March 2017 at 19:07, Brett Cannon wrote: > I'm overall very supportive of seeing something like this make it into > Python to further strengthen duck typing in the language. > Thanks! > Personally, I think even an abstract method should be properly typed. > [SNIP] > or raise NotImplement

Re: [Python-Dev] PEP 544: Protocols

2017-03-20 Thread Brett Cannon
I'm overall very supportive of seeing something like this make it into Python to further strengthen duck typing in the language. I know I've wanted something something like this since ABCs were introduced. I personally only have one issue/clarification for the PEP. On Mon, 20 Mar 2017 at 05:02 Iv

[Python-Dev] why _PyGen_Finalize(gen) propagates close() to _PyGen_yf() ?

2017-03-20 Thread Oleg Nesterov
Hello, Let me first clarify, I do not claim this is a bug, I am trying to learn python and now I trying to understand yield-from. This simple test-case g = (x for x in range(10)) def fg(): for x in g: yield x print(next(fg()))

[Python-Dev] __del__ is not called after creating a new reference

2017-03-20 Thread Oleg Nesterov
Hello, I already tried to ask on python-list, see https://mail.python.org/pipermail/python-list/2017-March/720037.html but it seems that this list is not for technical questions. Let me resend my question to python-dev. Please tell me if I should not spam this list with newbiesh questions, and th

Re: [Python-Dev] Py_SIZE vs PyXXX_GET_SIZE

2017-03-20 Thread Brett Cannon
On Mon, 20 Mar 2017 at 04:28 Serhiy Storchaka wrote: > What is the preferable way of getting the size of tuple, list, bytes, > bytearray: Py_SIZE or PyTuple_GET_SIZE, PyList_GET_SIZE, > PyBytes_GET_SIZE, PyByteArray_GET_SIZE? Are macros for concrete types > more preferable or they are outdated? >

[Python-Dev] PEP 544: Protocols

2017-03-20 Thread Ivan Levkivskyi
Hi all, PEP 484 specifies semantics for type hints. These type hints are used by various tools, including static type checkers. However, PEP 484 only specifies the semantics for nominal subtyping (subtyping based on subclassing). Here we propose a specification for semantics of structural subtypin

[Python-Dev] Py_SIZE vs PyXXX_GET_SIZE

2017-03-20 Thread Serhiy Storchaka
What is the preferable way of getting the size of tuple, list, bytes, bytearray: Py_SIZE or PyTuple_GET_SIZE, PyList_GET_SIZE, PyBytes_GET_SIZE, PyByteArray_GET_SIZE? Are macros for concrete types more preferable or they are outdated? On one hand concrete type macros are longer than Py_SIZE, a