Open mezarque opened 2 weeks ago
Some validation that this is the reason:
from copy import deepcopy
deepcopy(apc.teal)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[6], [line 3](vscode-notebook-cell:?execution_count=6&line=3)
[1](vscode-notebook-cell:?execution_count=6&line=1) from copy import deepcopy
----> [3](vscode-notebook-cell:?execution_count=6&line=3) deepcopy(apc.teal)
File ~/miniconda3/envs/apc/lib/python3.12/copy.py:162, in deepcopy(x, memo, _nil)
[160](https://file+.vscode-resource.vscode-cdn.net/Users/dennis/Code/arcadia-pycolor/~/miniconda3/envs/apc/lib/python3.12/copy.py:160) y = x
[161](https://file+.vscode-resource.vscode-cdn.net/Users/dennis/Code/arcadia-pycolor/~/miniconda3/envs/apc/lib/python3.12/copy.py:161) else:
--> [162](https://file+.vscode-resource.vscode-cdn.net/Users/dennis/Code/arcadia-pycolor/~/miniconda3/envs/apc/lib/python3.12/copy.py:162) y = _reconstruct(x, memo, *rv)
[164](https://file+.vscode-resource.vscode-cdn.net/Users/dennis/Code/arcadia-pycolor/~/miniconda3/envs/apc/lib/python3.12/copy.py:164) # If is its own copy, don't memoize.
[165](https://file+.vscode-resource.vscode-cdn.net/Users/dennis/Code/arcadia-pycolor/~/miniconda3/envs/apc/lib/python3.12/copy.py:165) if y is not x:
File ~/miniconda3/envs/apc/lib/python3.12/copy.py:253, in _reconstruct(x, memo, func, args, state, listiter, dictiter, deepcopy)
[251](https://file+.vscode-resource.vscode-cdn.net/Users/dennis/Code/arcadia-pycolor/~/miniconda3/envs/apc/lib/python3.12/copy.py:251) if deep and args:
[252](https://file+.vscode-resource.vscode-cdn.net/Users/dennis/Code/arcadia-pycolor/~/miniconda3/envs/apc/lib/python3.12/copy.py:252) args = (deepcopy(arg, memo) for arg in args)
--> [253](https://file+.vscode-resource.vscode-cdn.net/Users/dennis/Code/arcadia-pycolor/~/miniconda3/envs/apc/lib/python3.12/copy.py:253) y = func(*args)
[254](https://file+.vscode-resource.vscode-cdn.net/Users/dennis/Code/arcadia-pycolor/~/miniconda3/envs/apc/lib/python3.12/copy.py:254) if deep:
[255](https://file+.vscode-resource.vscode-cdn.net/Users/dennis/Code/arcadia-pycolor/~/miniconda3/envs/apc/lib/python3.12/copy.py:255) memo[id(x)] = y
File ~/miniconda3/envs/apc/lib/python3.12/copyreg.py:99, in __newobj__(cls, *args)
[98](https://file+.vscode-resource.vscode-cdn.net/Users/dennis/Code/arcadia-pycolor/~/miniconda3/envs/apc/lib/python3.12/copyreg.py:98) def __newobj__(cls, *args):
---> [99](https://file+.vscode-resource.vscode-cdn.net/Users/dennis/Code/arcadia-pycolor/~/miniconda3/envs/apc/lib/python3.12/copyreg.py:99) return cls.__new__(cls, *args)
TypeError: HexCode.__new__() missing 1 required positional argument: 'hex_code'
Overview
When trying to use
HexCode
objects inplotly
(not currently supported), we can run into problems caused by the way thatplotly
handles color objects; namely, that it usesdeepcopy
at some point in the figure generation process to create a copy of an input color object. Because of the way we developedHexCode
to inherit fromstr
, we don't currently override the__copy__
or__deepcopy__
methods. My guess is that this results in a problem whendeepcopy
is used on aHexCode
object.Example
Example Plotly code that causes an error:
Full traceback of error:
Solution
For now, users can use the
.hex_code
property of aHexCode
object to circumvent this limitation of our implementation. In the long term, we should consider implementing overrides of__copy__
and__deepcopy__
intoHexCode
to more easily supportplotly
.