Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

type of UserList instance returns class instead of instance #48576

Closed
chafporte mannequin opened this issue Nov 14, 2008 · 11 comments
Closed

type of UserList instance returns class instead of instance #48576

chafporte mannequin opened this issue Nov 14, 2008 · 11 comments
Labels
type-bug An unexpected behavior, bug, or error

Comments

@chafporte
Copy link
Mannequin

chafporte mannequin commented Nov 14, 2008

BPO 4326
Nosy @birkenfeld, @rhettinger, @benjaminp

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2008-11-14.22:04:41.830>
created_at = <Date 2008-11-14.21:36:31.281>
labels = ['type-bug']
title = 'type of UserList instance returns class instead of instance'
updated_at = <Date 2008-11-18.08:00:44.648>
user = 'https://bugs.python.org/chafporte'

bugs.python.org fields:

activity = <Date 2008-11-18.08:00:44.648>
actor = 'georg.brandl'
assignee = 'none'
closed = True
closed_date = <Date 2008-11-14.22:04:41.830>
closer = 'benjamin.peterson'
components = ['None']
creation = <Date 2008-11-14.21:36:31.281>
creator = 'chafporte'
dependencies = []
files = []
hgrepos = []
issue_num = 4326
keywords = []
message_count = 11.0
messages = ['75885', '75887', '75888', '75891', '75893', '75896', '75897', '75898', '75905', '75978', '76002']
nosy_count = 4.0
nosy_names = ['georg.brandl', 'rhettinger', 'benjamin.peterson', 'chafporte']
pr_nums = []
priority = 'normal'
resolution = 'wont fix'
stage = None
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue4326'
versions = ['Python 2.6']

@chafporte
Copy link
Mannequin Author

chafporte mannequin commented Nov 14, 2008

from UserList import UserList
lu = UserList()
type(lu)

python2.6 prints: <class 'UserList.UserList'>
python2.5 prints: <type 'instance'>

@chafporte chafporte mannequin added the type-bug An unexpected behavior, bug, or error label Nov 14, 2008
@rhettinger
Copy link
Contributor

That is because UserList is now a new-style class as a result of it
inheriting from the new abstract base classes. I believe this is the
way Guido wanted it and do not see any deleterious impacts from the change.

Recommend closing as "won't fix" or "invalid".

@benjaminp
Copy link
Contributor

Isn't policy to keep old-style classes around for compatibility in 2.x?
Especially one like UserList which is meant to be used as a base class.

@rhettinger
Copy link
Contributor

It has been the practice to not switch old-style to new-style just for
the hell of it. However, we do switch as part of large PEP driven
efforts like the ABC backport.

@benjaminp
Copy link
Contributor

Fair enough.

@chafporte
Copy link
Mannequin Author

chafporte mannequin commented Nov 14, 2008

but like that there is no way to detect if the object
is a class or an instance. type() says it's a class in both case !

@rhettinger
Copy link
Contributor

>>> import inspect
>>> from UserList import UserList
>>> lu = UserList()
>>> inspect.isclass(UserList)
True
>>> inspect.isclass(lu)
False

@chafporte
Copy link
Mannequin Author

chafporte mannequin commented Nov 14, 2008

but for a user define class we have:

class AAA:
... pass

a = AAA()
type(a)
<type 'instance'>
and you can compare this with types.InstanceType
and it says True

where for the UserList instance the comparison with
types.InstanceType says False

it is just not homogenous. and it make the comparison with
types.InstanceType unusable !!!

are you sure this is not breaking the API ?

@birkenfeld
Copy link
Member

What good is a comparison with InstanceType for? If you want to check
whether it's an instance of a custom class, you'll have to check for
instances of new-style classes anyway. If you want to check for UserList
instances, use isinstance().

@chafporte
Copy link
Mannequin Author

chafporte mannequin commented Nov 17, 2008

but in python 2.5 you may do this:

if type(lInstance) == types.InstanceType:
    ...
else:
    ...

and I don't see an easy way to do this with python 2.6
(feel free to propose a solution if you have one)

@birkenfeld
Copy link
Member

I repeat, what is this "easy" condition good for?

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants