Skip to content

Commit

Permalink
Cleanup: Fix Mypy errors in init1.py
Browse files Browse the repository at this point in the history
  • Loading branch information
hoh committed Sep 20, 2023
1 parent 2b39b16 commit afe69d3
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions runtimes/aleph-debian-11-python/init1.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from io import StringIO
from os import system
from shutil import make_archive
from typing import Any, AsyncIterable, Dict, List, NewType, Optional, Tuple, Union
from typing import Any, AsyncIterable, Dict, List, NewType, Optional, Tuple, Union, cast

import aiohttp
import msgpack
Expand Down Expand Up @@ -62,9 +62,9 @@ class ConfigurationPayload:
input_data: bytes
interface: Interface
vm_hash: str
code: bytes = None
encoding: Encoding = None
entrypoint: str = None
code: bytes
encoding: Encoding
entrypoint: str
ip: Optional[str] = None
ipv6: Optional[str] = None
route: Optional[str] = None
Expand Down Expand Up @@ -225,7 +225,7 @@ def setup_code_asgi(
app = locals[entrypoint]
else:
raise ValueError(f"Unknown encoding '{encoding}'")
return app
return ASGIApplication(app)


def setup_code_executable(
Expand Down Expand Up @@ -261,9 +261,9 @@ def setup_code_executable(


def setup_code(
code: Optional[bytes],
encoding: Optional[Encoding],
entrypoint: Optional[str],
code: bytes,
encoding: Encoding,
entrypoint: str,
interface: Interface,
) -> Union[ASGIApplication, subprocess.Popen]:
if interface == Interface.asgi:
Expand All @@ -284,15 +284,15 @@ async def run_python_code_http(
# Execute in the same process, saves ~20ms than a subprocess

# The body should not be part of the ASGI scope itself
body: bytes = scope.pop("body")
request_body: bytes = scope.pop("body")

async def receive():
type_ = (
"http.request"
if scope["type"] in ("http", "websocket")
else "aleph.message"
)
return {"type": type_, "body": body, "more_body": False}
return {"type": type_, "body": request_body, "more_body": False}

send_queue: asyncio.Queue = asyncio.Queue()

Expand All @@ -311,13 +311,13 @@ async def send(dico):
headers = {}

logger.debug("Waiting for body")
body: Dict = await send_queue.get()
response_body: Dict = await send_queue.get()

logger.debug("Waiting for buffer")
output = buf.getvalue()

logger.debug(f"Headers {headers}")
logger.debug(f"Body {body}")
logger.debug(f"Body {response_body}")
logger.debug(f"Output {output}")

logger.debug("Getting output data")
Expand All @@ -330,7 +330,7 @@ async def send(dico):
output_data = b""

logger.debug("Returning result")
return headers, body, output, output_data
return headers, response_body, output, output_data


async def make_request(session, scope):
Expand Down Expand Up @@ -429,6 +429,7 @@ async def process_instruction(
output_data: Optional[bytes]

if interface == Interface.asgi:
application = cast(ASGIApplication, application)
headers, body, output, output_data = await run_python_code_http(
application=application, scope=payload.scope
)
Expand Down

0 comments on commit afe69d3

Please sign in to comment.