class(obj) could return obj.__class__

Please, consider class(obj) to return obj.__class__ consistenly with dir(), vars(), repr(), str(),…
class c: pass o = c() o.__class__
<class '__main__.c'>
class(o)
File "<stdin>", line 1 class(o) ^ SyntaxError: invalid syntax
H.

Please use type(o) instead.
On Tue, Feb 9, 2021 at 4:36 PM Hans Ginzel hans@matfyz.cz wrote:
Please, consider class(obj) to return obj.__class__ consistenly with dir(), vars(), repr(), str(),…
class c: pass o = c() o.__class__
<class '__main__.c'>
class(o)
File "<stdin>", line 1 class(o) ^ SyntaxError: invalid syntax
H. _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-leave@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/TMFUKI... Code of Conduct: http://python.org/psf/codeofconduct/

On Tue, Feb 9, 2021 at 6:39 PM Hans Ginzel hans@matfyz.cz wrote:
Please, consider class(obj) to return obj.__class__ consistenly with dir(), vars(), repr(), str(),…
class c: pass o = c() o.__class__
<class '__main__.c'>
class(o)
File "<stdin>", line 1 class(o) ^ SyntaxError: invalid syntax
It's spelled type(ob), because syntactically, "class" is special. :)
ChrisA
participants (3)
-
Chris Angelico
-
Hans Ginzel
-
Inada Naoki