PEP8, Pylint

This commit is contained in:
DarkCat09 2022-12-25 18:19:28 +04:00
parent c02d3fed3e
commit c788976ab2
3 changed files with 21 additions and 14 deletions

View file

@ -163,6 +163,7 @@ good-names=i,
k,
f,
s,
js,
ex,
Run,
_

View file

@ -24,7 +24,6 @@ class Interpreter(abc.ABC):
def __init__(self) -> None:
"""Base JS interpreter class"""
pass
def __getitem__(self, name: str) -> Any:
"""Support for `js[name]` syntax
@ -45,7 +44,6 @@ class Interpreter(abc.ABC):
Args:
func (str): JS function
"""
pass
@abc.abstractmethod
def get_var(self, name: str) -> Any:
@ -58,10 +56,11 @@ class Interpreter(abc.ABC):
Returns:
Variable value
"""
pass
class NodeInterpreter(Interpreter):
"""Node.JS interpreter wrapper,
starts a simple web server in background"""
def __init__(
self,
@ -84,12 +83,14 @@ class NodeInterpreter(Interpreter):
self.url = f'http://{host}:{port}'
# pylint: disable=consider-using-with
self.proc = subprocess.Popen(
args=[
node, server_js,
f'{port}', host,
],
)
# pylint: enable=consider-using-with
time.sleep(0.1)
def exec_js(self, func: str) -> None:
@ -107,11 +108,15 @@ class NodeInterpreter(Interpreter):
class Js2PyInterpreter(Interpreter):
"""Js2Py interpreter,
uses js2py library to execute code"""
# Thanks to http://regex.inginf.units.it
arrowexp = regex.compile(r'\w[^\}]*+')
def __init__(self) -> None:
"""Js2Py interpreter,
uses js2py library to execute code"""
super().__init__()
@ -179,8 +184,9 @@ def atob(s: str) -> str:
def get_interpreter(
*args,
create: Type[Interpreter] = Js2PyInterpreter,
*args, **kwargs) -> 'Interpreter':
**kwargs) -> 'Interpreter':
"""Get or create a JS interpreter.
`*args` and `**kwargs` will be passed
directly to JS interpreter `__init__`
@ -193,7 +199,7 @@ def get_interpreter(
JS interpreter instance
"""
global js
global js # pylint: disable=global-statement
# create if none
if js is None: