Skip to content

Commit

Permalink
Cleanup code
Browse files Browse the repository at this point in the history
  • Loading branch information
tusharsadhwani committed Oct 9, 2023
1 parent dc30686 commit da9662e
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/interpreted/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ def repr(self) -> str:


class Module(Object):
def __init__(self, attrs: {str: Scope}):
self.attributes = attrs
def __init__(self, members: dict[str, Object]):
super().__init__()
self.attributes.update(members)


class Function(Object):
Expand Down Expand Up @@ -423,7 +424,7 @@ def visit_Import(self, node: Import) -> None:
self.scope = parent_scope
self.globals = parent_globals

module_obj = Module(attrs=vars(module_scope))
module_obj = Module(members=vars(module_scope))

self.scope.set(name, module_obj)

Expand All @@ -450,15 +451,15 @@ def visit_ImportFrom(self, node: ImportFrom) -> None:
for alias in node.names:
name = alias.name
if name == "*":
for attr in module_scope.__dict__:
self.scope.set(attr, module_scope.get(attr))
break
for member, value in vars(module_scope).items():
self.scope.set(member, value)
return

if alias.asname:
name = alias.asname

body = module_scope.get(alias.name)
self.scope.set(name, body)
member = module_scope.get(alias.name)
self.scope.set(name, member)

def visit_FunctionDef(self, node: FunctionDef) -> None:
function = UserFunction(node, self.globals)
Expand Down

0 comments on commit da9662e

Please sign in to comment.