[Python-Dev] Aaron Hall, Introduction and pull-request bump

2017-09-11 Thread Aaron Hall via Python-Dev
Hi there,
I have had the privilege of getting to know some core developers at PyCon in 
Portland, and I've met some others through my volunteering at PyGotham and the 
NYC Python meetup group (resisting urge to name-drop). 
In spite of not joining the mailing list until about a week ago at Brett 
Cannon's suggestion, I have managed to submit 3 bug-report fixes, with 1 closed 
by pull-request, 1 nearly closed with the pull-request accepted, and 1 with the 
pull request not yet accepted (looks like there's a conflict in misc/NEWS now, 
not sure how to use Github to resolve it either). That last pull request is 
here: bpo-26103 resolve Data descriptor contradiction by aaronchall · Pull 
Request #1959 · python/cpython - probably good if


|  |  | 
bpo-26103 resolve Data descriptor contr...
 |


I also had a "MutableNamedTuple" implementation I put on 
codereview.stackexchange.com 
(https://codereview.stackexchange.com/q/173045/23451) and Ashwini Chaudhury 
gave me some excellent pointers, and inspired by the recent discussion on "Data 
Classes" I now have a half-baked implementation that leverages __slots__ with a 
Mapping, for example (from a unittest, hence the indentation):
    class MNTDemo(MutableNamedTuple):
    "Demo"
    __slots__ = {
    'arg0': arg(),
    'arg1': arg(typing.List),
    'kwarg': arg(default=0), # must be positional if passed *args
    'args': arg(stars=Stars.ARGS),
    # everything after *args must be keyword argument
    'kwarg1': arg(list, []), 
    'kwarg2': None,
    'kwargs': arg(typing.Any, stars=Stars.KWARGS) 
    }
    mnt = MNTDemo(1, 2, 3, 'stararg1',
              kwarg1=1, kwarg2=2, kwarg3=3)
Maybe there's a nicer way to do it, but arg is a function returning a 
namedtuple (attrs: type, default, stars) with some defaults. It allows the 
__init__ to have required positional arguments and required named arguments, 
pretty much as flexible as a regular function signature, but communicated via 
__slots__. And thanks to the slots, they're every bit as performant as a 
namedtuple, I presume (I gave the __slots__ talk at PyCon).
Anyways, to wrap up my introduction, I'm a moderator on StackOverflow 
(https://stackoverflow.com/users/541136/aaron-hall?tab=profile) and nearly 
about to catch Raymond in reputation points, mostly due to Python, I'm 
currently teaching Python at NYU (Introduction to Programming), and I'm an 
all-around Python evangelist (as much as I know how to be.) I owe a lot to the 
Python community, especially the meetup community in NYC, but also virtual 
community (Ned Batchelder in IRC comes to mind). 
Thank you for everything, I'm looking for my chance to give back!
Cheers, 
Aaron Hall___
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Issues with PEP 526 Variable Notation at the class level

2017-12-09 Thread Aaron Hall via Python-Dev
 I'm not a typing expert, but I want to second Raymond's concerns, and perhaps 
I'm qualified to do so as I gave the PyCon USA __slots__ talk this year and I 
have a highly voted answer describing them on Stack Overflow.
Beautiful thing we're doing here with the dataclasses, by the way. I think 
addressing the slots issue could be a killer feature of dataclasses.

I hope this doesn't muddy the water:

If I could change a couple of things about __slots__ it would be 1. to allow 
multiple inheritance with multiple parents with nonempty slots (raises 
"TypeError: multiple bases have instance lay-out conflict"), and
2. to avoid creating redundant slots if extant in a parent (but maybe we should 
do this in the C level for all classes?).

It seems to me that Dataclasses could (and should) help us avoid the second 
issue regardless (should be trivial to look in the bases for preexisting slots, 
right?).

My workaround for the first issue is to inherit from ABCs with empty slots, but 
you need cooperative multiple inheritance for this - and you need to track the 
expected attributes (easy if you use abstract properties, which slots provide 
for. Maybe not all users of Dataclasses are advanced enough to do this?

So, maybe this is crazy (please don't call the nice men in white coats on me), 
came to me as I was responding, and definitely outside the box here, but 
perhaps we could make decorated dataclass be the abstract parent of the 
instantiated class?

Thanks,
Aaron Hall

On Friday, December 8, 2017, 1:31:44 PM EST, Raymond Hettinger 
 wrote:  
 The way __slots__ works is that the type() metaclass automatically assigns 
member-objects to the class variables 'x' and 'y'.  Member objects are 
descriptors that do the actual lookup.

So, I don't think the language limitation can be "fixed".  Essentially, we're 
wanting to use the class variables 'x' and 'y' to hold both member objects and 
a default value.

I recommend that you follow the path taken by attrs and return a new class.  
Otherwise, we're leaving users with a devil's choice.  You can have default 
values or you can have slots, but you can't have both.

The slots are pretty important.  With slots, a three attribute instance is only 
64 bytes.  Without slots, it is 296 bytes.

I'm hoping the typing experts will chime in here.  The question is 
straight-forward.  Where should we look for the signature and docstring for 
constructing instances?  Should they be attached to the class, to __init__(), 
or to __new__() when it used.

It would be nice to have an official position on that before, it gets set in 
stone through arbitrary choices made by pycharm, pydoc, mypy, 
typing.NamedTuple, and dataclasses.dataclass.


Raymond




___
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/aaronchall%40yahoo.com
  ___
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com