[issue33268] iteration over attrs in metaclass' __new__ affects class' __name__

2018-04-12 Thread tkhyn

tkhyn  added the comment:

oops,  indeed. Sometimes the obvious things are not so obvious ..
Sorry for the noise!

--

___
Python tracker 

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



[issue33268] iteration over attrs in metaclass' __new__ affects class' __name__

2018-04-12 Thread Eric V. Smith

Eric V. Smith  added the comment:

In the loop, you're reassigning the value of name, then using it in the super 
call. If you change the name of the loop variable, your code works.

--
nosy: +eric.smith
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed
type:  -> behavior

___
Python tracker 

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



[issue33268] iteration over attrs in metaclass' __new__ affects class' __name__

2018-04-12 Thread tkhyn

New submission from tkhyn :

The following script, run with python 3.6.5, highlights an issue with the 
class' __name__ attribute being set incorrectly just because of a loop in the 
metaclass' __new__ method:

class MC(type):
def __new__(mcs, name, bases, attrs):
for name, attr in attrs.items():
pass
return super(MC, mcs).__new__(mcs, name, bases, attrs)

class C(metaclass=MC):
a = None

print(C.__name__)


Expected output: "C"
Actual output: "a"

Comment the for loop and you get the expected output!

On Python 2.7.13, the amended code exposes the same bug:

class MC(type):
def __new__(mcs, name, bases, attrs):
for name, attr in attrs.items():
pass
return super(MC, mcs).__new__(mcs, name, bases, attrs)

class C(object):
__metaclass__ = MC
a = None

print C.__name__

output is "__metaclass__" and should be "C"

--
components: Interpreter Core
messages: 315218
nosy: tkhyn
priority: normal
severity: normal
status: open
title: iteration over attrs in metaclass' __new__ affects class' __name__
versions: Python 2.7, Python 3.6

___
Python tracker 

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