[issue41629] __class__ not set defining 'X' as . Was __classcell__ propagated to type.__new__?

2020-08-25 Thread Karthikeyan Singaravelan


Karthikeyan Singaravelan  added the comment:

Related SO questions : 

* 
https://stackoverflow.com/questions/61543768/super-in-a-typing-namedtuple-subclass-fails-in-python-3-8
* 
https://stackoverflow.com/questions/41343263/provide-classcell-example-for-python-3-6-metaclass

--

___
Python tracker 

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



[issue41629] __class__ not set defining 'X' as . Was __classcell__ propagated to type.__new__?

2020-08-25 Thread Karthikeyan Singaravelan


Karthikeyan Singaravelan  added the comment:

The example used to raise deprecation warning in python 3.7

python3.7 -Wall ../backups/bpo41629.py
../backups/bpo41629.py:4: DeprecationWarning: __class__ not set defining 'X' as 
. Was __classcell__ propagated to type.__new__?
  class X(NamedTuple):

It was converted into RuntimeError in 
https://github.com/python/cpython/commit/f5e7b1999f46e592d42dfab51563ea5411946fb7
 . Related https://bugs.python.org/issue23722

--
nosy: +xtreak

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



[issue41629] __class__ not set defining 'X' as . Was __classcell__ propagated to type.__new__?

2020-08-24 Thread mike bayer


New submission from mike bayer :

This is likely related or a dupe of https://bugs.python.org/issue29270, but the 
error message is different.  I'm posting this to confirm it's the same issue, 
or not, and to at least provide a google result for people who also see this 
error as 29270 seems to imply this might not be fixable.

Like 29270, it involves the fact that the interpreter seems to be looking at my 
super() call inside of a method without actually calling it, and then getting 
upset about __classcell__:



from typing import NamedTuple


class X(NamedTuple):
a: str
b: str

# comment this out to remove the issue
def foo(self):
return super(X, self)


and that's it!  on my interpreter:

Python 3.8.3 (default, May 23 2020, 16:34:37) 
[GCC 9.3.1 20200408 (Red Hat 9.3.1-2)] on linux

I get:

$ python test3.py 
Traceback (most recent call last):
  File "test3.py", line 4, in 
class X(NamedTuple):
RuntimeError: __class__ not set defining 'X' as . Was 
__classcell__ propagated to type.__new__?

The most surprising thing is that this seems extremely basic and google is not 
finding this error message for me.

--
components: Interpreter Core
messages: 375863
nosy: zzzeek
priority: normal
severity: normal
status: open
title: __class__ not set defining 'X' as . Was 
__classcell__ propagated to type.__new__?
versions: Python 3.8

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



[issue39904] Move handling of one-argument call of type() from type.__new__() to type.__call__()

2020-03-09 Thread Serhiy Storchaka


Change by Serhiy Storchaka :


--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

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



[issue39904] Move handling of one-argument call of type() from type.__new__() to type.__call__()

2020-03-09 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:


New changeset 413f01352a8268fb62bb47bde965462d7b82a06a by Serhiy Storchaka in 
branch 'master':
bpo-39904: Move handling of one-argument call of type() from type.__new__() to 
type.__call__(). (GH-18852)
https://github.com/python/cpython/commit/413f01352a8268fb62bb47bde965462d7b82a06a


--

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



[issue39904] Move handling of one-argument call of type() from type.__new__() to type.__call__()

2020-03-08 Thread Serhiy Storchaka


Change by Serhiy Storchaka :


--
keywords: +patch
pull_requests: +18209
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/18852

___
Python tracker 

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



[issue39904] Move handling of one-argument call of type() from type.__new__() to type.__call__()

2020-03-08 Thread Serhiy Storchaka


New submission from Serhiy Storchaka :

The builtin type() serves two functions:

1. When called with a single positional argument it returns the type of the 
argument.

>>> type(1)


2. Otherwise it acts as any class when called -- creates an instance of this 
class (a type). It includes calling corresponding __new__ and __init__ methods.

>>> type('A', (str,), {'foo': lambda self: len(self)})


type is a class, and it can be subclassed. Subclasses of type serve only the 
latter function (the former was forbidden in issue27157).

>>> class T(type): pass
... 
>>> T(1)
Traceback (most recent call last):
  File "", line 1, in 
TypeError: type.__new__() takes exactly 3 arguments (1 given)
>>> T('A', (str,), {'foo': lambda self: len(self)})


But surprisingly you can use the __new__ method for getting the type of the 
object.

>>> type.__new__(type, 1)

>>> T.__new__(T, 1)
Traceback (most recent call last):
  File "", line 1, in 
TypeError: type.__new__() takes exactly 3 arguments (1 given)

The proposed PR moves handling the special case of one-argument type() from 
type.__new__ to type.__call__.

It does not fix any real bug, it does not add significant performance boost, it 
does not remove a lot of code, it just makes the code slightly more 
straightforward. It changes the behavior of type.__new__(type, obj) which is 
very unlikely called directly in real code.

>>> type(1)

>>> type.__new__(type, 1)
Traceback (most recent call last):
  File "", line 1, in 
TypeError: type.__new__() takes exactly 3 arguments (1 given)

--
components: Interpreter Core
messages: 363664
nosy: gvanrossum, serhiy.storchaka
priority: normal
severity: normal
status: open
title: Move handling of one-argument call of type() from type.__new__() to 
type.__call__()
versions: Python 3.9

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



[issue19888] type.__new__() name argument is ignored

2013-12-04 Thread Barry A. Warsaw

Changes by Barry A. Warsaw ba...@python.org:


--
title: possible memory corruption caused by for-loop iteration over 
namespace.items() in a metaclass defining __new__ - type.__new__() name 
argument is ignored

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



[issue19888] type.__new__() name argument is ignored

2013-12-04 Thread Barry A. Warsaw

Changes by Barry A. Warsaw ba...@python.org:


--
resolution: invalid - 
status: closed - open

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



[issue19888] type.__new__() name argument is ignored

2013-12-04 Thread Barry A. Warsaw

Changes by Barry A. Warsaw ba...@python.org:


--
versions: +Python 3.3, Python 3.4 -Python 2.7, Python 3.2

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



[issue19888] type.__new__() name argument is ignored

2013-12-04 Thread Barry A. Warsaw

Barry A. Warsaw added the comment:

At best, this is an undocumented (afaict) change in behavior in 3.3.  Let's 
boil it down:

-snip snip-
class Type(type):
def __new__(mcls, name, bases, namespace):
return super().__new__(mcls, 'foo', bases, namespace)

class Obj(metaclass=Type):
def __init__(self, **kwargs):
pass

print(repr(Obj))
-snip snip-

In = 3.2, this prints class '__main__.foo'

In = 3.3 this prints class '__main__.Obj'

So, clearly this is a change in behavior.  Was it intended?  If so, it's 
undocumented - I can find no mention of it in Misc/NEWS or What's New in 3.3.  
I suspect it is unintended.

--

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



[issue19888] type.__new__() name argument is ignored

2013-12-04 Thread Antoine Pitrou

Changes by Antoine Pitrou pit...@free.fr:


--
versions: +Python 2.7, Python 3.2

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



[issue19888] type.__new__() name argument is ignored

2013-12-04 Thread Antoine Pitrou

Antoine Pitrou added the comment:

Barry: that's because __name__ is 'foo' while __qualname__ is 'Obj'.

I'm gonna close the bug, since it's invalid.

--
nosy: +pitrou
resolution:  - invalid

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



[issue19888] type.__new__() name argument is ignored

2013-12-04 Thread Antoine Pitrou

Antoine Pitrou added the comment:

(you can open a new issue for the __name__ / __qualname__ discrepancy, though)

--

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



[issue19888] type.__new__() name argument is ignored

2013-12-04 Thread Benjamin Peterson

Changes by Benjamin Peterson benja...@python.org:


--
status: open - closed

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



type.__new__

2005-03-18 Thread Dirk Brenckmann
Hi there,

I'm new to this list and currently tracing down a problem...
Could anybody give me a hint, where I can find the implementation of
type.__new__. This should be somewhere in the 'c' sources - right?

I just want to read the code to see what this call really does.

Thanx for your time and help
Dirk Brenckmann

-- 
DSL Komplett von GMX +++ Supergünstig und stressfrei einsteigen!
AKTION Kein Einrichtungspreis nutzen: http://www.gmx.net/de/go/dsl
-- 
http://mail.python.org/mailman/listinfo/python-list