Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ name = "workers-py"
version = "1.6.1"
description = "A set of libraries and tools for Python Workers"
readme = "README.md"
requires-python = ">=3.11"
requires-python = ">=3.12"
classifiers = [
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
Expand All @@ -19,6 +19,7 @@ dependencies = [
"pyodide-cli",
"pyjson5>=1.6.0",
"pyodide-py",
"workers-runtime-sdk>=0.1.0",
]

[dependency-groups]
Expand Down
25 changes: 14 additions & 11 deletions tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
dev = [
"mypy>=1.17.1",
"pyodide-py",
"workers-runtime-sdk",
]

[tool.mypy]
Expand All @@ -26,16 +27,18 @@
"""

WORKER = """
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from js import Env

class Default:
env: "Env"
async def fetch(self) -> None:
reveal_type(self.env.FOO) # Revealed type is "js.KVNamespace_iface"
from workers import WorkerEntrypoint, Response, Request


class Default(WorkerEntrypoint):
async def fetch(self, request: Request) -> Response:
reveal_type(self.env)
reveal_type(self.env.FOO)
await self.env.FOO.put("bar", "baz")
bar = await self.env.FOO.get("bar")
reveal_type(bar) # Revealed type is "builtins.str | None"
assert bar
reveal_type(bar)
return Response(bar)
"""


Expand All @@ -53,7 +56,7 @@ def test_types(tmp_path):
with chdir(tmp_path):
wrangler_types(None, None)
result = run(["uv", "run", "mypy"], capture_output=True, text=True, check=False)

assert 'Revealed type is "js.Env"' in result.stdout
assert 'Revealed type is "js.KVNamespace_iface"' in result.stdout
assert 'Revealed type is "builtins.str | None"' in result.stdout
assert 'Revealed type is "builtins.str"' in result.stdout
assert "Success: no issues found" in result.stdout