P2PySonar2demo_project/pysonar_demo/strategies.pyView source
pysonar_demo/strategies.pyStatic analysis
C3 inheritance, overrides, class methods, and static methods.24 definitions34 references
   1 """Multiple-inheritance and override examples for semantic navigation."""
   2
   3
   4 class BaseStrategy:
   5     def adjust(self, score: float) -> float:
   6         return score
   7
   8     def audit_label(self) -> str:
   9         return "base"
  10
  11
  12 class AuditedStrategy(BaseStrategy):
  13     """Keeps the base implementation while contributing audit behavior."""
  14
  15     def audit(self, score: float) -> str:
  16         return self.audit_label() + ":" + str(score)
  17
  18
  19 class WeightedStrategy(BaseStrategy):
  20     def adjust(self, score: float) -> float:
  21         return min(1.0, score * 1.02)
  22
  23     def audit_label(self) -> str:
  24         return "weighted"
  25
  26
  27 class AuditedMarketStrategy(AuditedStrategy, WeightedStrategy):
  28     """C3 resolves inherited methods through WeightedStrategy before BaseStrategy."""
  29
  30     @classmethod
  31     def strategy_name(cls) -> str:
  32         return cls.__name__
  33
  34     @staticmethod
  35     def supports_live_markets() -> bool:
  36         return True