diff --git a/src/pip/_internal/locations/_sysconfig.py b/src/pip/_internal/locations/_sysconfig.py index 97aef1f1ac2..9dd802a3a22 100644 --- a/src/pip/_internal/locations/_sysconfig.py +++ b/src/pip/_internal/locations/_sysconfig.py @@ -1,3 +1,4 @@ +import dataclasses import logging import os import sys @@ -192,9 +193,10 @@ def get_scheme( data=paths["data"], ) if root is not None: + converted_keys = {} for key in SCHEME_KEYS: - value = change_root(root, getattr(scheme, key)) - setattr(scheme, key, value) + converted_keys[key] = change_root(root, getattr(scheme, key)) + scheme = dataclasses.replace(scheme, **converted_keys) return scheme diff --git a/src/pip/_internal/models/scheme.py b/src/pip/_internal/models/scheme.py index 4ca61fe0cce..06a9a550e34 100644 --- a/src/pip/_internal/models/scheme.py +++ b/src/pip/_internal/models/scheme.py @@ -10,7 +10,7 @@ SCHEME_KEYS = ["platlib", "purelib", "headers", "scripts", "data"] -@dataclass +@dataclass(frozen=True) class Scheme: """A Scheme holds paths which are used as the base directories for artifacts associated with a Python package.