mirror of
https://github.com/torvalds/linux.git
synced 2026-09-24 06:24:02 +02:00
perf jevents metric: Add python type annotations
Make mypy clean. Signed-off-by: Ian Rogers <irogers@google.com> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
This commit is contained in:
parent
cda907c2c3
commit
59355235f2
|
|
@ -276,7 +276,7 @@ class Operator(Expression):
|
|||
lhs = self.lhs.Simplify()
|
||||
rhs = self.rhs.Simplify()
|
||||
if isinstance(lhs, Constant) and isinstance(rhs, Constant):
|
||||
return Constant(ast.literal_eval(lhs + self.operator + rhs))
|
||||
return Constant(ast.literal_eval(lhs.value + self.operator + rhs.value))
|
||||
|
||||
if isinstance(self.lhs, Constant):
|
||||
if self.operator in ('+', '|') and lhs.value == '0':
|
||||
|
|
@ -298,7 +298,7 @@ class Operator(Expression):
|
|||
if self.operator == '*' and rhs.value == '0':
|
||||
return Constant(0)
|
||||
|
||||
if self.operator == '*' and self.rhs.value == '1':
|
||||
if self.operator == '*' and rhs.value == '1':
|
||||
return lhs
|
||||
|
||||
return Operator(self.operator, lhs, rhs)
|
||||
|
|
@ -316,9 +316,7 @@ class Operator(Expression):
|
|||
if self.Equals(expression):
|
||||
return Event(name)
|
||||
lhs = self.lhs.Substitute(name, expression)
|
||||
rhs = None
|
||||
if self.rhs:
|
||||
rhs = self.rhs.Substitute(name, expression)
|
||||
rhs = self.rhs.Substitute(name, expression)
|
||||
return Operator(self.operator, lhs, rhs)
|
||||
|
||||
|
||||
|
|
@ -382,7 +380,9 @@ class Function(Expression):
|
|||
rhs: Optional[Union[int, float, Expression]] = None):
|
||||
self.fn = fn
|
||||
self.lhs = _Constify(lhs)
|
||||
self.rhs = _Constify(rhs)
|
||||
self.rhs = None
|
||||
if rhs is not None:
|
||||
self.rhs = _Constify(rhs)
|
||||
|
||||
def ToPerfJson(self):
|
||||
if self.rhs:
|
||||
|
|
@ -407,7 +407,8 @@ class Function(Expression):
|
|||
return Function(self.fn, lhs, rhs)
|
||||
|
||||
def HasExperimentalEvents(self) -> bool:
|
||||
return self.lhs.HasExperimentalEvents() or (self.rhs and self.rhs.HasExperimentalEvents())
|
||||
return (self.lhs.HasExperimentalEvents() or
|
||||
(self.rhs is not None and self.rhs.HasExperimentalEvents()))
|
||||
|
||||
def Equals(self, other: Expression) -> bool:
|
||||
if isinstance(other, Function):
|
||||
|
|
@ -683,7 +684,7 @@ class MetricGroup:
|
|||
|
||||
def Flatten(self) -> Set[Metric]:
|
||||
"""Returns a set of all leaf metrics."""
|
||||
result = set()
|
||||
result: Set[Metric] = set()
|
||||
for x in self.metric_list:
|
||||
result = result.union(x.Flatten())
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user