[issue17421] Drop restriction that meta.__prepare__() must return a dict (subclass)

2019-03-12 Thread Caleb Donovick


Caleb Donovick  added the comment:

In my mind this seems like a bug. PEP 3115 states:
'''
__prepare__ returns a dictionary-like object which is used to store the class 
member definitions during evaluation of the class body. In other words, the 
class body is evaluated as a function block (just like it is now), except that 
the local variables dictionary is replaced by the dictionary returned from 
__prepare__. This dictionary object can be a regular dictionary or a custom 
mapping type.
'''

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17421] Drop restriction that meta.__prepare__() must return a dict (subclass)

2019-03-12 Thread Caleb Donovick


Change by Caleb Donovick :


--
nosy: +donovick

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17421] Drop restriction that meta.__prepare__() must return a dict (subclass)

2017-09-26 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

> Are you sure that non-dicts work fine?

They don't. See issue31588.

--
dependencies: +SystemError in class creation in case of a metaclass with a bad 
__prepare__() method
nosy: +serhiy.storchaka

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17421] Drop restriction that meta.__prepare__() must return a dict (subclass)

2016-09-09 Thread Eric Snow

Changes by Eric Snow :


--
assignee: eric.snow -> 

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17421] Drop restriction that meta.__prepare__() must return a dict (subclass)

2015-07-21 Thread Ethan Furman

Changes by Ethan Furman et...@stoneleaf.us:


--
nosy:  -ethan.furman

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17421
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17421] Drop restriction that meta.__prepare__() must return a dict (subclass)

2014-05-20 Thread STINNER Victor

Changes by STINNER Victor victor.stin...@gmail.com:


--
nosy: +haypo

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17421
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17421] Drop restriction that meta.__prepare__() must return a dict (subclass)

2014-05-18 Thread Ethan Furman

Changes by Ethan Furman et...@stoneleaf.us:


--
nosy: +ethan.furman

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17421
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17421] Drop restriction that meta.__prepare__() must return a dict (subclass)

2013-06-24 Thread Eric Snow

Changes by Eric Snow ericsnowcurren...@gmail.com:


--
assignee:  - eric.snow

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17421
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17421] Drop restriction that meta.__prepare__() must return a dict (subclass)

2013-03-16 Thread Nick Coghlan

Nick Coghlan added the comment:

Eric and I discussed this, and I've come to the conclusion that the check 
doesn't serve much purpose at this point.

I initially thought it conveyed useful information about the runtime 
behavioural restriction, but it doesn't even do that correctly, as dict 
subclasses (like collections.OrderedDict) will pass the check but will also be 
copied into a vanilla dict instance.

However, we definitely shouldn't drop it until the copying behaviour is 
properly documented, so I've added #17422 as an explicit dependency.

--
dependencies: +language reference should specify restrictions on class namespace

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17421
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17421] Drop restriction that meta.__prepare__() must return a dict (subclass)

2013-03-14 Thread Eric Snow

New submission from Eric Snow:

Currently type_new() in Objects/typeobject.c enforces a restriction that the 
namespace be a dict or dict subclass.  It does this via the 
PyArg_ParseTupleAndKeywords() call there.

This means that valid mappings may not be used even though they should work 
just fine.  A demonstration of the problem is below.

I've attached a patch that relaxes this restriction.  Should we also add a note 
in the docs that type() will take anything for namespace that dict() will take?

Demonstration
-

class Meta(type):
@classmethod
def __prepare__(cls, name, bases, **kwargs):
return ClassMapping()

from collections import MutableMapping
class ClassMapping(MutableMapping):
def __init__(self, *args, **kwargs):
self._dict = dict(*args, **kwargs)
def __len__(self):
  return len(self._dict)
def __iter__(self):
return iter(self._dict)
def __getitem__(self, key):
return self._dict[key]
def __setitem__(self, key, value):
self._dict[key] = value
def __delitem__(self, key):
del self._dict[key]

 class X(metaclass=Meta):
... pass
...
Traceback (most recent call last):
  File stdin, line 1, in module
TypeError: type() argument 3 must be dict, not ClassMapping

--
files: type-namespace-restriction.diff
keywords: patch
messages: 184187
nosy: eric.snow, ncoghlan
priority: normal
severity: normal
stage: patch review
status: open
title: Drop restriction that meta.__prepare__() must return a dict (subclass)
type: enhancement
versions: Python 3.4
Added file: http://bugs.python.org/file29408/type-namespace-restriction.diff

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17421
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17421] Drop restriction that meta.__prepare__() must return a dict (subclass)

2013-03-14 Thread Daniel Urban

Changes by Daniel Urban urban.dani...@gmail.com:


--
nosy: +daniel.urban

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17421
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17421] Drop restriction that meta.__prepare__() must return a dict (subclass)

2013-03-14 Thread Martin v . Löwis

Martin v. Löwis added the comment:

Are you sure that non-dicts work fine? ISTM that there is quite some code that 
relies on tp_dict being a dict-or-subdict instance, e.g. in 
typeobject.c:type_module,type_get_doc etc.

--
nosy: +loewis

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17421
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17421] Drop restriction that meta.__prepare__() must return a dict (subclass)

2013-03-14 Thread Eric Snow

Eric Snow added the comment:

Sorry I wasn't clear.  Later in type.__new__() it copies that passed namespace 
into a new dict (see issue #17422).  So as long as the namespace argument is a 
valid argument to dict(), it's going to work fine.  We don't need the extra 
explicit check performed by PyArg_ParseTupleAndKeywords().

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17421
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com