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

operator "is" #46273

Closed
shigin mannequin opened this issue Jan 31, 2008 · 5 comments
Closed

operator "is" #46273

shigin mannequin opened this issue Jan 31, 2008 · 5 comments
Labels
type-bug An unexpected behavior, bug, or error

Comments

@shigin
Copy link
Mannequin

shigin mannequin commented Jan 31, 2008

BPO 1981
Nosy @gvanrossum, @birkenfeld, @amauryfa

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-01-31.16:19:03.952>
created_at = <Date 2008-01-31.16:17:01.568>
labels = ['type-bug']
title = 'operator "is"'
updated_at = <Date 2008-02-01.16:04:22.063>
user = 'https://bugs.python.org/shigin'

bugs.python.org fields:

activity = <Date 2008-02-01.16:04:22.063>
actor = 'gvanrossum'
assignee = 'none'
closed = True
closed_date = <Date 2008-01-31.16:19:03.952>
closer = 'georg.brandl'
components = []
creation = <Date 2008-01-31.16:17:01.568>
creator = 'shigin'
dependencies = []
files = []
hgrepos = []
issue_num = 1981
keywords = []
message_count = 5.0
messages = ['61905', '61906', '61907', '61908', '61962']
nosy_count = 4.0
nosy_names = ['gvanrossum', 'georg.brandl', 'amaury.forgeotdarc', 'shigin']
pr_nums = []
priority = 'normal'
resolution = 'duplicate'
stage = None
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue1981'
versions = ['Python 2.5', 'Python 2.4']

@shigin
Copy link
Mannequin Author

shigin mannequin commented Jan 31, 2008

Hello,

The operator "is" works strange with methods, i.e.:

>>> a = 1
>>> a.__abs__ is a.__abs__
False

If this is the preferred behavior by some reasons, I think
documentation should explain it.

It was tested on python 2.4.4, 2.5.1 and trunk r60477.

@shigin shigin mannequin added the type-bug An unexpected behavior, bug, or error label Jan 31, 2008
@birkenfeld
Copy link
Member

Yes, it is expected since the descriptor access to methods creates a new
bound method object every time. The "is" operator does not work special
with methods.

There is another issue about documenting this, so closing as a duplicate.

@amauryfa
Copy link
Member

It's actually documented in
http://docs.python.org/dev/reference/datamodel.html

"""
Note that the transformation from function object to (unbound or bound)
method object happens each time the attribute is retrieved from the
class or instance
"""

@shigin
Copy link
Mannequin Author

shigin mannequin commented Jan 31, 2008

I think it's good idea to make a note in Comparisons section or make
some reference to data model section.

"""
The operators is and is not test for object identity: x is y is true if
and only if x and y are the same object. x is not y yields the inverse
truth value.
"""

But,
>>> id(a.__abs__) == id(a.__abs__)
True

And only example below shows me error in my objection.
>>> id(w)
6636344
>>> p = id(w)
>>> del w
>>> e = 1
>>> id(e)
6636344

I'm sorry for spam. I've missed bpo-1410739 when search for any open
bug.

@gvanrossum
Copy link
Member

id(a.__abs__) == id(a.__abs__)

has a completely different explanation -- it so happens that the first
instantiation of a.__abs__ is freed after id() is called on it and the
second instantiation happens to reuse that same memory block.

@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