Skip to content
Snippets Groups Projects
Commit 8e1405af authored by Frederik Hennig's avatar Frederik Hennig
Browse files

fix mutable defaults error with Category descriptor and Python 3.12

parent 25d7040d
Branches
Tags
1 merge request!448Fix mutable-default bug in codegen.config with Python 3.11 and newer
Pipeline #73030 failed
......@@ -86,8 +86,8 @@ def typecheck(session: nox.Session):
session.run("mypy", "src/pystencils")
@nox.session(python=["3.10", "3.12", "3.13"], tags=["test"])
@nox.parametrize("cupy_version", [None, "12", "13"], ids=["cpu", "cupy12", "cupy13"])
@nox.session(python="3.10", tags=["test"])
def testsuite(session: nox.Session, cupy_version: str | None):
if cupy_version is not None:
install_cupy(session, cupy_version, skip_if_no_cuda=True)
......
......@@ -196,12 +196,16 @@ class Category(Generic[Category_T]):
def __get__(self, obj: ConfigBase, objtype: type[ConfigBase] | None = None) -> Category_T:
if obj is None:
return self._default
return None
return cast(Category_T, getattr(obj, self._lookup, None))
cat = getattr(obj, self._lookup, None)
if cat is None:
cat = self._default.copy()
setattr(obj, self._lookup, cat)
return cast(Category_T, cat)
def __set__(self, obj: ConfigBase, cat: Category_T):
setattr(obj, self._lookup, cat.copy())
def __set__(self, obj: ConfigBase, cat: Category_T | None):
setattr(obj, self._lookup, cat.copy() if cat is not None else None)
class _AUTO_TYPE: ... # noqa: E701
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment