Skip to content

Commit

Permalink
Fix block as_dict. Fix pyright problem
Browse files Browse the repository at this point in the history
  • Loading branch information
Nfsaavedra committed Apr 24, 2024
1 parent 4171002 commit a2e362b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
5 changes: 4 additions & 1 deletion glitch/parsers/puppet.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,10 @@ def process_hash_value(
args = []
for arg in codeelement.parameters:
attr = PuppetParser.__process_codeelement(arg, path, code)
args.append(Variable(attr.name, "", True))
variable = Variable(attr.name, "", True)
variable.line = arg.line
variable.column = arg.col
args.append(Variable(variable))
return (
list(
map(
Expand Down
21 changes: 19 additions & 2 deletions glitch/repr/inter.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from abc import ABC
from enum import Enum
from typing import List, Union, Dict, Any
from types import NoneType


class CodeElement(ABC):
Expand Down Expand Up @@ -38,11 +37,29 @@ def __init__(self) -> None:
def add_statement(self, statement: "ConditionalStatement") -> None:
self.statements.append(statement)

@staticmethod
def __as_dict_statement(
stat: Dict[str, Any] | List[Any] | CodeElement | str
) -> Any:
if isinstance(stat, CodeElement):
return stat.as_dict()
elif isinstance(stat, dict):
for key, value in stat.items():
stat[key] = Block.__as_dict_statement(value)
return stat
elif isinstance(stat, list):
return [Block.__as_dict_statement(s) for s in stat]
else:
return stat

def as_dict(self) -> Dict[str, Any]:
print(self.statements)
for statement in self.statements:
print(type(statement))
return {
**super().as_dict(),
"statements": [
s.as_dict() if not isinstance(s, str) else s for s in self.statements
Block.__as_dict_statement(s) for s in self.statements # type: ignore
],
}

Expand Down

0 comments on commit a2e362b

Please sign in to comment.