[issue11604] Have type(n,b,d) check for type(b[i]) is module

2020-11-16 Thread Terry J. Reedy


Terry J. Reedy  added the comment:

I cannot anymore remember seeing this. So closing.

--
resolution:  -> out of date
stage: test needed -> resolved
status: pending -> closed

___
Python tracker 

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



[issue11604] Have type(n,b,d) check for type(b[i]) is module

2020-11-16 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

Special cases aren't special enough to break the rules.

I think this issue should be closed. This is not common user error, especially 
in Python 3. I can even imagine that you can subclass module, if it is an 
instance of special ModuleType subclass. It is a feature of Python that you can 
subclass any objects, not only classes, if they provide the particular 
interface.

--
nosy: +serhiy.storchaka
status: open -> pending

___
Python tracker 

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



[issue11604] Have type(n,b,d) check for type(b[i]) is module

2020-11-16 Thread Irit Katriel


Change by Irit Katriel :


--
keywords: +newcomer friendly
versions: +Python 3.10, Python 3.9 -Python 3.3

___
Python tracker 

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



[issue11604] Have type(n,b,d) check for type(b[i]) is module

2011-07-13 Thread Éric Araujo

Éric Araujo mer...@netwok.org added the comment:

I don’t know if this should be left to lint tools or addressed by CPython 
itself.  Raymond, do you have an opinion?

--
nosy: +rhettinger

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



[issue11604] Have type(n,b,d) check for type(b[i]) is module

2011-03-20 Thread Éric Araujo

Éric Araujo mer...@netwok.org added the comment:

 raise TypeError('Cannot subclass module')
It is possible to subclass module.

Ray: right, but 2.x still has a long life ahead of it, so we still want to 
improve its doc.

--
nosy: +eric.araujo

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



[issue11604] Have type(n,b,d) check for type(b[i]) is module

2011-03-20 Thread Terry J. Reedy

Terry J. Reedy tjre...@udel.edu added the comment:

Whoops. That should be 'Cannot subclass a module' or 'Cannot subclass module 
%s' % modulename.  Types.ModuleType can indeed by subclassed.

I agree that this is not a pressing issue, but it will at least provide an 
answer to anyone searching the tracker for the current message.

--

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



[issue11604] Have type(n,b,d) check for type(b[i]) is module

2011-03-19 Thread Ray.Allen

Ray.Allen ysj@gmail.com added the comment:

 I am only suggesting a check for module because the is the only mistake  I 
 remember anyone reporting. Passing a number as a base class gives a   
 similar message, but no one does that. And as far as I know, there is  no 
 way in general to detect whether a callable works as a metaclass  except by 
 calling it with name, bases, and dict.


Since 3.x all the module names became lower-case and can be easily differ from 
class names, so I don't think this problem will present much in 3.x, right?

--
nosy: +ysj.ray

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



[issue11604] Have type(n,b,d) check for type(b[i]) is module

2011-03-18 Thread Terry J. Reedy

New submission from Terry J. Reedy tjre...@udel.edu:

People occasionally ask on python-list about the following error message when 
trying to create a class:

 TypeError: Error when calling the metaclass bases
 module.__init__() takes at most 2 arguments (3 given)

It is a bit cryptic. It is also accidental: if module.__init__ happened to take 
3 args instead of 2, the exception would be delayed until ???

The cause is using a module as a superclass, as in

import UserDict
class MyDict(UserDict): pass

This seems to happen mostly because of duplicate (or only case-different) 
module/class names.
 
Suggestion: insert a specific module type check for bases in type_new() in 
typeobject.c. In Python:
  if basetype is module: # where 'module' is the module class
raise TypeError('Cannot subclass module')

I see 2 possible places to put the check:

1. for all bases - after
tmp = PyTuple_GET_ITEM(bases, i);
tmptype = Py_TYPE(tmp);

Advantage: can add (name of) tmp to the error message.

2. Before the return call in
if (winner != metatype) {
if (winner-tp_new != type_new) /* Pass it to the winner */
return winner-tp_new(winner, args, kwds);

Advantage: only add extra check when module is the winner and are about to call 
it as a metaclass, which raises the current error.

Any test would be CPython specific and would require checking something about 
the message text.

I am only suggesting a check for module because the is the only mistake I 
remember anyone reporting. Passing a number as a base class gives a similar 
message, but no one does that. And as far as I know, there is no way in general 
to detect whether a callable works as a metaclass except by calling it with 
name, bases, and dict.

--
components: Interpreter Core
messages: 131381
nosy: terry.reedy
priority: normal
severity: normal
stage: test needed
status: open
title: Have type(n,b,d) check for type(b[i]) is module
type: feature request
versions: Python 3.3

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