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

pydantic.color.Color is not hashable in 1.10.0 release #4454

Closed
7 of 16 tasks
Czaki opened this issue Aug 31, 2022 · 2 comments · Fixed by #4455
Closed
7 of 16 tasks

pydantic.color.Color is not hashable in 1.10.0 release #4454

Czaki opened this issue Aug 31, 2022 · 2 comments · Fixed by #4455
Labels
bug V1 Bug related to Pydantic V1.X

Comments

@Czaki
Copy link
Contributor

Czaki commented Aug 31, 2022

Initial Checks

  • I have searched GitHub for a duplicate issue and I'm sure this is something new
  • I have searched Google & StackOverflow for a solution and couldn't find anything
  • I have read and followed the docs and still think this is a bug
  • I am confident that the issue is with pydantic (not my code, or another library in the ecosystem like FastAPI or mypy)

Description

In pydantic 1.9.2 (and earlier), the Color class was Hashable. in release 1.10.0 it is not hashable that broke usage color as an argument to function decorated with @lru_cache from std lib. (napari/napari#4995)

A I do not see public method for mutate such object IO thin that it is deprecation.

Example Code

pydantic 1.9.2

In [1]: from pydantic.color import Color                                                     

In [2]: a = Color((0,0,0))                                                                   

In [3]: hash(a)                                                                              
Out[3]: 8771047785283

pydantic 1.10.0

In [1]: from pydantic.color import Color                                                     

In [2]: a = Color((0,0,0))                                                                   

In [3]: hash(a)                                                                              
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-3-57b555d30865> in <module>
----> 1 hash(a)

TypeError: unhashable type: 'Color'


### Python, Pydantic & OS Version

```Text
pydantic 1.9.2 vs pydantic 1.10.0 tested on ubuntu and macos m1.

Affected Components

@Czaki Czaki added bug V1 Bug related to Pydantic V1.X unconfirmed Bug not yet confirmed as valid/applicable labels Aug 31, 2022
@samuelcolvin
Copy link
Member

Thanks so much for reporting, I've added napari to #4359.

Confirmed. Seems this was an unexpected side effect of #3646 I didn't know that adding __eq__ brakes hashing.

PR welcome to fix this, otherwise I'll do it soon.

@samuelcolvin samuelcolvin removed the unconfirmed Bug not yet confirmed as valid/applicable label Aug 31, 2022
@Czaki
Copy link
Contributor Author

Czaki commented Aug 31, 2022

I just found it here (second paragraph): https://docs.python.org/3/reference/datamodel.html#object.__hash__, but also do not know earlier.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug V1 Bug related to Pydantic V1.X
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants