[issue33190] problem with ABCMeta.__prepare__ when called after types.new_class

2018-03-30 Thread Rick Teachey

Rick Teachey  added the comment:

Thank you; I gave it a go. Hopefully didn't cause too much additional work for 
someone.

--

___
Python tracker 

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



[issue33190] problem with ABCMeta.__prepare__ when called after types.new_class

2018-03-30 Thread Rick Teachey

Change by Rick Teachey :


--
keywords: +patch
pull_requests: +6033
stage:  -> patch review

___
Python tracker 

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



[issue33190] problem with ABCMeta.__prepare__ when called after types.new_class

2018-03-30 Thread Ivan Levkivskyi

Ivan Levkivskyi  added the comment:

https://devguide.python.org/ will help you.

--

___
Python tracker 

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



[issue33190] problem with ABCMeta.__prepare__ when called after types.new_class

2018-03-30 Thread Rick Teachey

Rick Teachey  added the comment:

Excellent; thank you very much for the explanation.

I have never done a PR on a project this size but I'll give it a try.

--

___
Python tracker 

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



[issue33190] problem with ABCMeta.__prepare__ when called after types.new_class

2018-03-30 Thread Ivan Levkivskyi

Ivan Levkivskyi  added the comment:

This is not a bug, but a misunderstanding:

* First, ABCMeta doesn't have `__prepare__`, it is just `type.__prepare__`
* Second, the third argument to `types.new_class` is called `kwds` for a 
reason. It is not a namespace like in `type` but the set of keywords in the 
equivalent class definition. For example:

types.new_class('Test', (A, B), {'metaclass': Meta, 'foo': 42})

id equivalent to

class Test(A, B, metaclass=Meta, foo=42):
pass

If you want to populate the namespace, then you should use the fourth argument 
`exec_body` which should be a callable that takes newly created dictionary and 
populates it with items. For your case it should be:

C = new_class("C", (MyABC,), {}, exec_body=lambda ns: ns.update(namespace))

If you want to clarify the corresponding docstring, then please open a PR. 
Otherwise you can close the issue.

--

___
Python tracker 

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



[issue33190] problem with ABCMeta.__prepare__ when called after types.new_class

2018-03-30 Thread Rick Teachey

New submission from Rick Teachey :

I am pretty sure this is a bug. If not I apologize.

Say I want to dynamically create a new `C` class, with base class `MyABC` (and 
dynamically assigned abstract method `m`). This works fine if I use `type`, but 
if I use `new_class`, the keyword argument to the `m` method implementation 
gets lost somewhere in the call to `ABCMeta.__prepare___`.

I've attached a file to demo. Thanks.

--
components: Library (Lib)
files: abcmeta_prepare.py
messages: 314714
nosy: Ricyteach, levkivskyi
priority: normal
severity: normal
status: open
title: problem with ABCMeta.__prepare__ when called after types.new_class
type: behavior
versions: Python 3.7, Python 3.8
Added file: https://bugs.python.org/file47509/abcmeta_prepare.py

___
Python tracker 

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