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

hashable and mutable functions #42395

Closed
cybb20 mannequin opened this issue Sep 21, 2005 · 4 comments
Closed

hashable and mutable functions #42395

cybb20 mannequin opened this issue Sep 21, 2005 · 4 comments
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@cybb20
Copy link
Mannequin

cybb20 mannequin commented Sep 21, 2005

BPO 1297986
Nosy @mwhudson, @birkenfeld, @rhettinger

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 2005-09-22.09:20:10.000>
created_at = <Date 2005-09-21.17:55:31.000>
labels = ['type-feature', 'library']
title = 'hashable and mutable functions'
updated_at = <Date 2005-09-22.09:20:10.000>
user = 'https://bugs.python.org/cybb20'

bugs.python.org fields:

activity = <Date 2005-09-22.09:20:10.000>
actor = 'rhettinger'
assignee = 'none'
closed = True
closed_date = None
closer = None
components = ['Library (Lib)']
creation = <Date 2005-09-21.17:55:31.000>
creator = 'cybb20'
dependencies = []
files = []
hgrepos = []
issue_num = 1297986
keywords = []
message_count = 4.0
messages = ['54619', '54620', '54621', '54622']
nosy_count = 4.0
nosy_names = ['mwh', 'georg.brandl', 'rhettinger', 'cybb20']
pr_nums = []
priority = 'normal'
resolution = 'rejected'
stage = None
status = 'closed'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue1297986'
versions = []

@cybb20
Copy link
Mannequin Author

cybb20 mannequin commented Sep 21, 2005

It is not easy to check if an object is hashable, ie
hasattr(list(), '__hash__') -> True

try: hash(list())
except TypeError: pass

seems to be a possible way to see if an object is
hashable, however it is not satisfiable that this
information needs to be retrieved by using exception
handling.

My proposal:
There should be a hashable(obj) function returning a
bool object and additionally it would be nice to have
something like ismutable(obj) function, possibly as
built-in functions.

Reason:
callable() is a built-in function and returns
information about an object whether it's callable or
not, that is a basic info about this object.
If an object is hashable or mutable is a state of an
object that is also very important to know.

@cybb20 cybb20 mannequin closed this as completed Sep 21, 2005
@cybb20 cybb20 mannequin added stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels Sep 21, 2005
@cybb20 cybb20 mannequin closed this as completed Sep 21, 2005
@cybb20 cybb20 mannequin added stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels Sep 21, 2005
@birkenfeld
Copy link
Member

Logged In: YES
user_id=1188172

try: hash(list())
except TypeError: pass

seems to be a possible way to see if an object is
hashable, however it is not satisfiable that this
information needs to be retrieved by using exception
handling.

Why?

My proposal:
There should be a hashable(obj) function returning a
bool object and additionally it would be nice to have
something like ismutable(obj) function, possibly as
built-in functions.

How should "ismutable" be implemented?

Reason:
callable() is a built-in function and returns
information about an object whether it's callable or
not, that is a basic info about this object.
If an object is hashable or mutable is a state of an
object that is also very important to know.

It's easier to ask for forgiveness than permission.

Even callable() has been called a mistake. Just call
it and see where you come.

So, -1.

@mwhudson
Copy link

Logged In: YES
user_id=6656

def ishashable(ob):
     try:
         hash(ob)
         return True
     except TypeError:
         return False

is the only reasonable way to implement this function (incidentally, do you
know how hasattr works?).

I don't see the need for a builtin, but am not feeling bolshy enough to just
close the tracker item. Maybe someone else does.

@rhettinger
Copy link
Contributor

Logged In: YES
user_id=80475

Adding a third -1 from me and closing the RFE.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

3 participants