From: Jean-François Nguyen Date: Mon, 28 Jun 2021 17:49:27 +0000 (+0200) Subject: soc.base: add socproperty(weak=True) for optional properties. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=3e1e203d35d2929bc7af20fa1f56617db6a40258;p=lambdasoc.git soc.base: add socproperty(weak=True) for optional properties. --- diff --git a/lambdasoc/soc/base.py b/lambdasoc/soc/base.py index 79cb6c2..ceb3663 100644 --- a/lambdasoc/soc/base.py +++ b/lambdasoc/soc/base.py @@ -14,14 +14,14 @@ from ..periph import Peripheral __all__ = ["socproperty", "SoC", "ConfigBuilder"] -def socproperty(cls, src_loc_at=0): +def socproperty(cls, *, weak=False, src_loc_at=0): name = tracer.get_var_name(depth=2 + src_loc_at) __name = "__{}".format(name) def getter(self): assert isinstance(self, SoC) attr = getattr(self, __name, None) - if attr is None: + if attr is None and not weak: raise NotImplementedError("SoC {!r} does not have a {}" .format(self, name)) return attr