pysonar_demo/decorators.pyStatic analysis
Decorator factories, returned object types, and descriptor aliases.23 definitions34 references
1 """Decorator factories and same-name descriptor aliases for semantic navigation.""" 2 3 4 class DemoCommand: 5 def __init__(self, name: str, handler): 6 self.name = name 7 self.handler = handler 8 9 def run(self, symbol: str) -> str: 10 return self.handler(symbol) 11 12 13 def command(name: str): 14 """Return a decorator that replaces a function with a command object.""" 15 16 def decorate(handler): 17 return DemoCommand(name, handler) 18 19 return decorate 20 21 22 @command("inspect") 23 def inspect_symbol(symbol: str) -> str: 24 return "semantic context for " + symbol 25 26 27 def normalize_symbol(symbol: str) -> str: 28 return symbol.strip().replace("-", "_") 29 30 31 class SymbolTools: 32 """The assignment keeps the original function in the same impact family.""" 33 34 normalize_symbol = staticmethod(normalize_symbol) 35 36 37 def build_command_registry() -> dict: 38 return {inspect_symbol.name: inspect_symbol}