from keras import backend
from keras import ops
from keras.api_export import keras_export
from keras.backend.common import global_state


@keras_export(
    [
        "keras.DTypePolicy",
        "keras.dtype_policies.DTypePolicy",
        "keras.mixed_precision.DTypePolicy",  # Legacy
        "keras.mixed_precision.Policy",  # Legacy
    ]
)
class DTypePolicy:
    """A dtype policy for a Keras layer.

    A dtype policy determines a layer's computation and variable dtypes. Each
    layer has a policy. Policies can be passed to the `dtype` argument of layer
    constructors, or a global policy can be set with
    `keras.config.set_dtype_policy`.

    Args:
        name: The policy name, which determines the compute and variable dtypes.
            Can be any dtype name, such as `"float32"` or `"float64"`,
            which causes both the compute and variable dtypes
            will be that dtype.
            Can also be the string `"mixed_float16"` or `"mixed_bfloat16"`,
            which causes the compute dtype to be `float16` or `bfloat16`
            and the variable dtype to be `float32`.

    Typically you only need to interact with dtype policies when using mixed
    precision, which is the use of float16 or bfloat16 for computations and
    float32 for variables. This is why the term `mixed_precision` appears in the
    API name. Mixed precision can be enabled by passing `"mixed_float16"` or
    `"mixed_bfloat16"` to `keras.mixed_precision.set_dtype_policy()`.

    >>> keras.config.set_dtype_policy("mixed_float16")
    >>> layer1 = keras.layers.Dense(10)
    >>> layer1.dtype_policy  # layer1 will automatically use mixed precision
    <DTypePolicy "mixed_float16">
    >>> # Can optionally override layer to use float32
    >>> # instead of mixed precision.
    >>> layer2 = keras.layers.Dense(10, dtype="float32")
    >>> layer2.dtype_policy
    <DTypePolicy "float32">
    >>> # Set policy back to initial float32.
    >>> keras.config.set_dtype_policy('float32')

    In the example above, passing `dtype="float32"` to the layer is
    equivalent to passing
    `dtype=keras.config.DTypePolicy("float32")`.
    In general, passing a dtype policy name to a layer is equivalent
    to passing the corresponding policy, so it is never necessary
    to explicitly construct a `DTypePolicy` object.
    """

    def __new__(cls, name):
        if not isinstance(name, str):
            raise TypeError(
                "'name' must be a string, such as 'mixed_float16'. "
                f"Received: name={name} (of type {type(name)})"
            )
        # For backwards compatibility
        # TODO: We should consider deprecating this behavior
        if cls is __class__:
            if name.startswith("int8"):
                return QuantizedDTypePolicy(name)
            return FloatDTypePolicy(name)
        return super().__new__(cls)

    def __init__(self, name):
        self._name = name
        self._compute_dtype = backend.floatx()
        self._variable_dtype = backend.floatx()

    def _parse_name(self, name):
        """Parses a `DTypePolicy` name into a compute and variable dtype.

        Args:
            name: The name of the policy.

        Returns:
            The `(compute_dtype, variable_dtype)` pair.
        """
        raise NotImplementedError

    @property
    def variable_dtype(self):
        """The variable dtype of this policy.

        This is the dtype layers will create their variables in, unless a layer
        explicitly chooses a different dtype. If this is different than
        `DTypePolicy.compute_dtype`, Layers will cast variables to
        the compute dtype to avoid type errors.

        Variable regularizers are run in the variable dtype, not the compute
        dtype.

        Returns:
            The variable dtype of this policy, as a string.
        """
        return self._variable_dtype

    @property
    def compute_dtype(self):
        """The compute dtype of this policy.

        This is the dtype layers will do their computations in. Typically layers
        output tensors with the compute dtype as well.

        Note that even if the compute dtype is float16 or bfloat16, hardware
        devices may not do individual adds, multiplies, and other fundamental
        operations in float16 or bfloat16, but instead may do some of them in
        float32 for numeric stability. The compute dtype is the dtype of the
        inputs and outputs of the ops that the layer executes.
        Internally, many ops will do certain internal calculations in
        float32 or some other device-internal intermediate format with higher
        precision than float16/bfloat16, to increase numeric stability.

        Returns:
            The compute dtype of this policy, as a string.
        """
        return self._compute_dtype

    @property
    def name(self):
        """Returns the name of this policy."""
        return self._name

    def convert_input(self, x, autocast, dtype):
        dtype = backend.standardize_dtype(dtype)
        if backend.is_tensor(x):
            if (
                autocast
                and backend.is_float_dtype(x.dtype)
                and x.dtype != dtype
            ):
                x = backend.cast(x, dtype=dtype)
            return x
        elif backend.is_keras_tensor(x):
            if (
                autocast
                and backend.is_float_dtype(x.dtype)
                and x.dtype != dtype
            ):
                x.dtype = dtype
            return x
        elif hasattr(x, "__array__"):
            return ops.convert_to_tensor(x, dtype=dtype)
        return x

    def get_config(self):
        return {"name": self.name}

    @classmethod
    def from_config(cls, config):
        return cls(**config)


@keras_export(
    ["keras.FloatDTypePolicy", "keras.dtype_policies.FloatDTypePolicy"]
)
class FloatDTypePolicy(DTypePolicy):
    def __init__(self, name):
        super().__init__(name)
        self._compute_dtype, self._variable_dtype = self._parse_name(name)
        # TODO: check that the current hardware supports the provided
        # dtype policy and raise/warn otherwise.

    def _parse_name(self, name):
        if name == "mixed_float16":
            return "float16", "float32"
        elif name == "mixed_bfloat16":
            return "bfloat16", "float32"
        try:
            dtype = backend.standardize_dtype(name)
            return dtype, dtype
        except ValueError:
            raise ValueError(
                f"Cannot convert '{name}' to a mixed precision "
                "FloatDTypePolicy. Valid policies include 'mixed_float16', "
                "'mixed_bfloat16', and the name of any float dtype such as "
                "'float32'."
            )

    def __repr__(self):
        return f'<FloatDTypePolicy "{self._name}">'


@keras_export(
    ["keras.QuantizedDTypePolicy", "keras.dtype_policies.QuantizedDTypePolicy"]
)
class QuantizedDTypePolicy(DTypePolicy):
    def __init__(self, name):
        super().__init__(name)
        self._quantization_mode, self._compute_dtype, self._variable_dtype = (
            self._parse_name(name)
        )

    def _parse_name(self, name):
        error_msg = (
            f"Cannot convert '{name}' to a QuantizedDTypePolicy. "
            "Valid policies include "
            "'int8_from_float32', 'int8_from_float16', 'int8_from_bfloat16', "
            "'int8_from_mixed_float16', 'int8_from_mixed_bfloat16'."
        )
        split_name = name.split("_from_")
        if len(split_name) != 2:
            raise ValueError(error_msg)
        mode, from_name = split_name
        if mode not in ("int8",):
            raise ValueError(error_msg)
        if from_name == "mixed_float16":
            return mode, "float16", "float32"
        elif from_name == "mixed_bfloat16":
            return mode, "bfloat16", "float32"
        try:
            dtype = backend.standardize_dtype(from_name)
            return mode, dtype, dtype
        except ValueError:
            raise ValueError(error_msg)

    @property
    def quantization_mode(self):
        """The quantization mode of this policy.

        Returns:
            The quantization mode of this policy, as a string.
        """
        return self._quantization_mode

    def __repr__(self):
        return f'<QuantizedDTypePolicy "{self._name}">'


@keras_export(
    [
        "keras.config.set_dtype_policy",
        "keras.mixed_precision.set_dtype_policy",  # Legacy
        "keras.mixed_precision.set_global_policy",  # Legacy
    ]
)
def set_dtype_policy(policy):
    """Sets the default dtype policy globally.

    Example:

    >>> keras.config.set_dtype_policy("mixed_float16")
    """
    if not isinstance(policy, DTypePolicy):
        if isinstance(policy, str):
            if policy.startswith("int8"):
                policy = QuantizedDTypePolicy(policy)
            else:
                policy = FloatDTypePolicy(policy)
        else:
            raise ValueError(
                "Invalid `policy` argument. "
                "Expected the string name of a policy "
                "(such as 'mixed_float16') or a `DTypePolicy` "
                f"instance. Received: policy={policy} "
                f"(of type {type(policy)})"
            )
    global_state.set_global_attribute("dtype_policy", policy)


@keras_export(
    [
        "keras.config.dtype_policy",
        "keras.mixed_precision.dtype_policy",  # Legacy
        "keras.mixed_precision.global_policy",  # Legacy
    ]
)
def dtype_policy():
    """Returns the current default dtype policy object."""
    policy = global_state.get_global_attribute("dtype_policy", None)
    if policy is None:
        policy = FloatDTypePolicy(backend.floatx())
        set_dtype_policy(policy)
    return policy

keras/dtype_policies/dtype_policy.py
from keras import backend
from keras import ops
from keras.api_export import keras_export
from keras.backend.common import global_state


@keras_export(
    [
        "keras.DTypePolicy",
        "keras.dtype_policies.DTypePolicy",
        "keras.mixed_precision.DTypePolicy",  # Legacy
        "keras.mixed_precision.Policy",  # Legacy
    ]
)
class DTypePolicy:
    """A dtype policy for a Keras layer.

    A dtype policy determines a layer's computation and variable dtypes. Each
    layer has a policy. Policies can be passed to the `dtype` argument of layer
    constructors, or a global policy can be set with
    `keras.config.set_dtype_policy`.

    Args:
        name: The policy name, which determines the compute and variable dtypes.
            Can be any dtype name, such as `"float32"` or `"float64"`,
            which causes both the compute and variable dtypes
            will be that dtype.
            Can also be the string `"mixed_float16"` or `"mixed_bfloat16"`,
            which causes the compute dtype to be `float16` or `bfloat16`
            and the variable dtype to be `float32`.

    Typically you only need to interact with dtype policies when using mixed
    precision, which is the use of float16 or bfloat16 for computations and
    float32 for variables. This is why the term `mixed_precision` appears in the
    API name. Mixed precision can be enabled by passing `"mixed_float16"` or
    `"mixed_bfloat16"` to `keras.mixed_precision.set_dtype_policy()`.

    >>> keras.config.set_dtype_policy("mixed_float16")
    >>> layer1 = keras.layers.Dense(10)
    >>> layer1.dtype_policy  # layer1 will automatically use mixed precision
    <DTypePolicy "mixed_float16">
    >>> # Can optionally override layer to use float32
    >>> # instead of mixed precision.
    >>> layer2 = keras.layers.Dense(10, dtype="float32")
    >>> layer2.dtype_policy
    <DTypePolicy "float32">
    >>> # Set policy back to initial float32.
    >>> keras.config.set_dtype_policy('float32')

    In the example above, passing `dtype="float32"` to the layer is
    equivalent to passing
    `dtype=keras.config.DTypePolicy("float32")`.
    In general, passing a dtype policy name to a layer is equivalent
    to passing the corresponding policy, so it is never necessary
    to explicitly construct a `DTypePolicy` object.
    """

    def __new__(cls, name):
        if not isinstance(name, str):
            raise TypeError(
                "'name' must be a string, such as 'mixed_float16'. "
                f"Received: name={name} (of type {type(name)})"
            )
        # For backwards compatibility
        # TODO: We should consider deprecating this behavior
        if cls is __class__:
            if name.startswith("int8"):
                return QuantizedDTypePolicy(name)
            return FloatDTypePolicy(name)
        return super().__new__(cls)

    def __getnewargs__(self):
        # To support `copy`, `deepcopy` and `pickle`
        return (self._name,)

    def __init__(self, name):
        self._name = name
        self._compute_dtype = backend.floatx()
        self._variable_dtype = backend.floatx()

    def _parse_name(self, name):
        """Parses a `DTypePolicy` name into a compute and variable dtype.

        Args:
            name: The name of the policy.

        Returns:
            The `(compute_dtype, variable_dtype)` pair.
        """
        raise NotImplementedError

    @property
    def variable_dtype(self):
        """The variable dtype of this policy.

        This is the dtype layers will create their variables in, unless a layer
        explicitly chooses a different dtype. If this is different than
        `DTypePolicy.compute_dtype`, Layers will cast variables to
        the compute dtype to avoid type errors.

        Variable regularizers are run in the variable dtype, not the compute
        dtype.

        Returns:
            The variable dtype of this policy, as a string.
        """
        return self._variable_dtype

    @property
    def compute_dtype(self):
        """The compute dtype of this policy.

        This is the dtype layers will do their computations in. Typically layers
        output tensors with the compute dtype as well.

        Note that even if the compute dtype is float16 or bfloat16, hardware
        devices may not do individual adds, multiplies, and other fundamental
        operations in float16 or bfloat16, but instead may do some of them in
        float32 for numeric stability. The compute dtype is the dtype of the
        inputs and outputs of the ops that the layer executes.
        Internally, many ops will do certain internal calculations in
        float32 or some other device-internal intermediate format with higher
        precision than float16/bfloat16, to increase numeric stability.

        Returns:
            The compute dtype of this policy, as a string.
        """
        return self._compute_dtype

    @property
    def name(self):
        """Returns the name of this policy."""
        return self._name

    def convert_input(self, x, autocast, dtype):
        dtype = backend.standardize_dtype(dtype)
        if backend.is_tensor(x):
            if (
                autocast
                and backend.is_float_dtype(x.dtype)
                and x.dtype != dtype
            ):
                x = backend.cast(x, dtype=dtype)
            return x
        elif backend.is_keras_tensor(x):
            if (
                autocast
                and backend.is_float_dtype(x.dtype)
                and x.dtype != dtype
            ):
                x.dtype = dtype
            return x
        elif hasattr(x, "__array__"):
            return ops.convert_to_tensor(x, dtype=dtype)
        return x

    def get_config(self):
        return {"name": self.name}

    @classmethod
    def from_config(cls, config):
        return cls(**config)


@keras_export(
    ["keras.FloatDTypePolicy", "keras.dtype_policies.FloatDTypePolicy"]
)
class FloatDTypePolicy(DTypePolicy):
    def __init__(self, name):
        super().__init__(name)
        self._compute_dtype, self._variable_dtype = self._parse_name(name)
        # TODO: check that the current hardware supports the provided
        # dtype policy and raise/warn otherwise.

    def _parse_name(self, name):
        if name == "mixed_float16":
            return "float16", "float32"
        elif name == "mixed_bfloat16":
            return "bfloat16", "float32"
        try:
            dtype = backend.standardize_dtype(name)
            return dtype, dtype
        except ValueError:
            raise ValueError(
                f"Cannot convert '{name}' to a mixed precision "
                "FloatDTypePolicy. Valid policies include 'mixed_float16', "
                "'mixed_bfloat16', and the name of any float dtype such as "
                "'float32'."
            )

    def __repr__(self):
        return f'<FloatDTypePolicy "{self._name}">'


@keras_export(
    ["keras.QuantizedDTypePolicy", "keras.dtype_policies.QuantizedDTypePolicy"]
)
class QuantizedDTypePolicy(DTypePolicy):
    def __init__(self, name):
        super().__init__(name)
        self._quantization_mode, self._compute_dtype, self._variable_dtype = (
            self._parse_name(name)
        )

    def _parse_name(self, name):
        error_msg = (
            f"Cannot convert '{name}' to a QuantizedDTypePolicy. "
            "Valid policies include "
            "'int8_from_float32', 'int8_from_float16', 'int8_from_bfloat16', "
            "'int8_from_mixed_float16', 'int8_from_mixed_bfloat16'."
        )
        split_name = name.split("_from_")
        if len(split_name) != 2:
            raise ValueError(error_msg)
        mode, from_name = split_name
        if mode not in ("int8",):
            raise ValueError(error_msg)
        if from_name == "mixed_float16":
            return mode, "float16", "float32"
        elif from_name == "mixed_bfloat16":
            return mode, "bfloat16", "float32"
        try:
            dtype = backend.standardize_dtype(from_name)
            return mode, dtype, dtype
        except ValueError:
            raise ValueError(error_msg)

    @property
    def quantization_mode(self):
        """The quantization mode of this policy.

        Returns:
            The quantization mode of this policy, as a string.
        """
        return self._quantization_mode

    def __repr__(self):
        return f'<QuantizedDTypePolicy "{self._name}">'


@keras_export(
    [
        "keras.config.set_dtype_policy",
        "keras.mixed_precision.set_dtype_policy",  # Legacy
        "keras.mixed_precision.set_global_policy",  # Legacy
    ]
)
def set_dtype_policy(policy):
    """Sets the default dtype policy globally.

    Example:

    >>> keras.config.set_dtype_policy("mixed_float16")
    """
    if not isinstance(policy, DTypePolicy):
        if isinstance(policy, str):
            if policy.startswith("int8"):
                policy = QuantizedDTypePolicy(policy)
            else:
                policy = FloatDTypePolicy(policy)
        else:
            raise ValueError(
                "Invalid `policy` argument. "
                "Expected the string name of a policy "
                "(such as 'mixed_float16') or a `DTypePolicy` "
                f"instance. Received: policy={policy} "
                f"(of type {type(policy)})"
            )
    global_state.set_global_attribute("dtype_policy", policy)


@keras_export(
    [
        "keras.config.dtype_policy",
        "keras.mixed_precision.dtype_policy",  # Legacy
        "keras.mixed_precision.global_policy",  # Legacy
    ]
)
def dtype_policy():
    """Returns the current default dtype policy object."""
    policy = global_state.get_global_attribute("dtype_policy", None)
    if policy is None:
        policy = FloatDTypePolicy(backend.floatx())
        set_dtype_policy(policy)
    return policy

keras/dtype_policies/dtype_policy.py
diff --git a/keras/dtype_policies/dtype_policy.py b/keras/dtype_policies/dtype_policy.py
index 7c8586c2a6e3..8734037f7d45 100644
--- a/keras/dtype_policies/dtype_policy.py
+++ b/keras/dtype_policies/dtype_policy.py
@@ -69,6 +69,10 @@ def __new__(cls, name):
             return FloatDTypePolicy(name)
         return super().__new__(cls)
 
+    def __getnewargs__(self):
+        # To support `copy`, `deepcopy` and `pickle`
+        return (self._name,)
+
     def __init__(self, name):
         self._name = name
         self._compute_dtype = backend.floatx()
diff --git a/keras/dtype_policies/dtype_policy_test.py b/keras/dtype_policies/dtype_policy_test.py
index 9df8dd0a85f2..7b3535e66a7a 100644
--- a/keras/dtype_policies/dtype_policy_test.py
+++ b/keras/dtype_policies/dtype_policy_test.py
@@ -61,6 +61,32 @@ def test_get_config_from_config(self):
         new_policy = DTypePolicy.from_config(config)
         self.assertEqual(new_policy.name, "mixed_float16")
 
+    def test_deepcopy(self):
+        """Test builtin serialization methods."""
+        import copy
+        import pickle
+
+        # copy.deepcopy
+        policy = DTypePolicy("mixed_float16")
+        copied_policy = copy.deepcopy(policy)
+        self.assertEqual(
+            repr(copied_policy), '<FloatDTypePolicy "mixed_float16">'
+        )
+        # copy.copy
+        copied_policy = copy.copy(policy)
+        self.assertEqual(
+            repr(copied_policy), '<FloatDTypePolicy "mixed_float16">'
+        )
+        # pickle
+        temp_dir = self.get_temp_dir()
+        with open(f"{temp_dir}/policy.pickle", "wb") as f:
+            pickle.dump(policy, f)
+        with open(f"{temp_dir}/policy.pickle", "rb") as f:
+            copied_policy = pickle.load(f)
+        self.assertEqual(
+            repr(copied_policy), '<FloatDTypePolicy "mixed_float16">'
+        )
+
 
 class FloatDTypePolicyTest(test_case.TestCase):
     def test_initialization_valid_name(self):

TypeError: DTypePolicy.__new__() when deepcopy(layer_instance)
Hello,

I use `Python==3.11.8` with `keras==3.1.1`.

When I create a layer instance and try to deepcopy this layer I receive the following error which did not happen before.


```python
>>> import keras
>>> import copy
>>> layer_obj = keras.layers.Dense(1)
>>> copy.deepcopy(layer_obj)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/romainegele/miniforge3/envs/dlp/lib/python3.11/copy.py", line 172, in deepcopy
    y = _reconstruct(x, memo, *rv)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/romainegele/miniforge3/envs/dlp/lib/python3.11/copy.py", line 271, in _reconstruct
    state = deepcopy(state, memo)
            ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/romainegele/miniforge3/envs/dlp/lib/python3.11/copy.py", line 146, in deepcopy
    y = copier(x, memo)
        ^^^^^^^^^^^^^^^
  File "/Users/romainegele/miniforge3/envs/dlp/lib/python3.11/copy.py", line 231, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
                             ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/romainegele/miniforge3/envs/dlp/lib/python3.11/copy.py", line 172, in deepcopy
    y = _reconstruct(x, memo, *rv)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/romainegele/miniforge3/envs/dlp/lib/python3.11/copy.py", line 265, in _reconstruct
    y = func(*args)
        ^^^^^^^^^^^
  File "/Users/romainegele/miniforge3/envs/dlp/lib/python3.11/copyreg.py", line 105, in __newobj__
    return cls.__new__(cls, *args)
           ^^^^^^^^^^^^^^^^^^^^^^^
TypeError: DTypePolicy.__new__() missing 1 required positional argument: 'name'
>>> >>> copy.deepcopy(layer_obj)
  File "<stdin>", line 1
    >>> copy.deepcopy(layer_obj)
    ^^
SyntaxError: invalid syntax
>>> Traceback (most recent call last):
  File "<stdin>", line 1
    Traceback (most recent call last):
               ^^^^^^^^^^^
SyntaxError: invalid syntax. Perhaps you forgot a comma?
>>>   File "<stdin>", line 1, in <module>
  File "<stdin>", line 1
    File "<stdin>", line 1, in <module>
IndentationError: unexpected indent
>>>   File "/Users/romainegele/miniforge3/envs/dlp/lib/python3.11/copy.py", line 172, in deepcopy
  File "<stdin>", line 1
    File "/Users/romainegele/miniforge3/envs/dlp/lib/python3.11/copy.py", line 172, in deepcopy
IndentationError: unexpected indent
>>>     y = _reconstruct(x, memo, *rv)
  File "<stdin>", line 1
    y = _reconstruct(x, memo, *rv)
IndentationError: unexpected indent
>>>         ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<stdin>", line 1
    ^^^^^^^^^^^^^^^^^^^^^^^^^^
IndentationError: unexpected indent
>>>   File "/Users/romainegele/miniforge3/envs/dlp/lib/python3.11/copy.py", line 271, in _reconstruct
  File "<stdin>", line 1
    File "/Users/romainegele/miniforge3/envs/dlp/lib/python3.11/copy.py", line 271, in _reconstruct
IndentationError: unexpected indent
>>>     state = deepcopy(state, memo)
  File "<stdin>", line 1
    state = deepcopy(state, memo)
IndentationError: unexpected indent
>>>             ^^^^^^^^^^^^^^^^^^^^^
  File "<stdin>", line 1
    ^^^^^^^^^^^^^^^^^^^^^
IndentationError: unexpected indent
>>>   File "/Users/romainegele/miniforge3/envs/dlp/lib/python3.11/copy.py", line 146, in deepcopy
  File "<stdin>", line 1
    File "/Users/romainegele/miniforge3/envs/dlp/lib/python3.11/copy.py", line 146, in deepcopy
IndentationError: unexpected indent
>>>     y = copier(x, memo)
  File "<stdin>", line 1
    y = copier(x, memo)
IndentationError: unexpected indent
>>>         ^^^^^^^^^^^^^^^
  File "<stdin>", line 1
    ^^^^^^^^^^^^^^^
IndentationError: unexpected indent
>>>   File "/Users/romainegele/miniforge3/envs/dlp/lib/python3.11/copy.py", line 231, in _deepcopy_dict
  File "<stdin>", line 1
    File "/Users/romainegele/miniforge3/envs/dlp/lib/python3.11/copy.py", line 231, in _deepcopy_dict
IndentationError: unexpected indent
>>>     y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "<stdin>", line 1
    y[deepcopy(key, memo)] = deepcopy(value, memo)
IndentationError: unexpected indent
>>>                              ^^^^^^^^^^^^^^^^^^^^^
  File "<stdin>", line 1
    ^^^^^^^^^^^^^^^^^^^^^
IndentationError: unexpected indent
>>>   File "/Users/romainegele/miniforge3/envs/dlp/lib/python3.11/copy.py", line 172, in deepcopy
  File "<stdin>", line 1
    File "/Users/romainegele/miniforge3/envs/dlp/lib/python3.11/copy.py", line 172, in deepcopy
IndentationError: unexpected indent
>>>     y = _reconstruct(x, memo, *rv)
  File "<stdin>", line 1
    y = _reconstruct(x, memo, *rv)
IndentationError: unexpected indent
>>>         ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<stdin>", line 1
    ^^^^^^^^^^^^^^^^^^^^^^^^^^
IndentationError: unexpected indent
>>>   File "/Users/romainegele/miniforge3/envs/dlp/lib/python3.11/copy.py", line 265, in _reconstruct
  File "<stdin>", line 1
    File "/Users/romainegele/miniforge3/envs/dlp/lib/python3.11/copy.py", line 265, in _reconstruct
IndentationError: unexpected indent
>>>     y = func(*args)
  File "<stdin>", line 1
    y = func(*args)
IndentationError: unexpected indent
>>>         ^^^^^^^^^^^
  File "<stdin>", line 1
    ^^^^^^^^^^^
IndentationError: unexpected indent
>>>   File "/Users/romainegele/miniforge3/envs/dlp/lib/python3.11/copyreg.py", line 105, in __newobj__
  File "<stdin>", line 1
    File "/Users/romainegele/miniforge3/envs/dlp/lib/python3.11/copyreg.py", line 105, in __newobj__
IndentationError: unexpected indent
>>>     return cls.__new__(cls, *args)
  File "<stdin>", line 1
    return cls.__new__(cls, *args)
IndentationError: unexpected indent
>>>            ^^^^^^^^^^^^^^^^^^^^^^^
  File "<stdin>", line 1
    ^^^^^^^^^^^^^^^^^^^^^^^
IndentationError: unexpected indent
>>> TypeError: DTypePolicy.__new__() missing 1 required positional argument: 'name'
```
