Skip to content

Commit

Permalink
chore: various type fixes (#1636)
Browse files Browse the repository at this point in the history
  • Loading branch information
mxschmitt committed Nov 8, 2022
1 parent 843d96e commit 982c703
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion playwright/_impl/_browser_context.py
Expand Up @@ -320,7 +320,7 @@ async def _record_into_har(
page: Optional[Page] = None,
url: Union[Pattern[str], str] = None,
) -> None:
params = {
params: Dict[str, Any] = {
"options": prepare_record_har_options(
{
"recordHarPath": har,
Expand Down
2 changes: 1 addition & 1 deletion playwright/_impl/_browser_type.py
Expand Up @@ -54,7 +54,7 @@ def __init__(
self, parent: ChannelOwner, type: str, guid: str, initializer: Dict
) -> None:
super().__init__(parent, type, guid, initializer)
_playwright: "Playwright"
self._playwright: "Playwright"

def __repr__(self) -> str:
return f"<BrowserType name={self.name} executable_path={self.executable_path}>"
Expand Down
2 changes: 1 addition & 1 deletion playwright/_impl/_connection.py
Expand Up @@ -290,7 +290,7 @@ def dispatch(self, msg: ParsedMessagePayload) -> None:
return

guid = msg["guid"]
method = msg.get("method")
method = msg["method"]
params = msg.get("params")
if method == "__create__":
assert params
Expand Down
6 changes: 3 additions & 3 deletions playwright/_impl/_js_handle.py
Expand Up @@ -17,7 +17,7 @@
from typing import TYPE_CHECKING, Any, Dict, List, Optional
from urllib.parse import ParseResult, urlparse, urlunparse

from playwright._impl._connection import ChannelOwner, from_channel
from playwright._impl._connection import Channel, ChannelOwner, from_channel
from playwright._impl._map import Map

if TYPE_CHECKING: # pragma: no cover
Expand Down Expand Up @@ -107,7 +107,7 @@ async def json_value(self) -> Any:


def serialize_value(
value: Any, handles: List[JSHandle], visitor_info: Optional[VisitorInfo] = None
value: Any, handles: List[Channel], visitor_info: Optional[VisitorInfo] = None
) -> Any:
if visitor_info is None:
visitor_info = VisitorInfo()
Expand Down Expand Up @@ -159,7 +159,7 @@ def serialize_value(


def serialize_argument(arg: Serializable = None) -> Any:
handles: List[JSHandle] = []
handles: List[Channel] = []
value = serialize_value(arg, handles)
return dict(value=value, handles=handles)

Expand Down
1 change: 1 addition & 0 deletions playwright/_impl/_json_pipe.py
Expand Up @@ -33,6 +33,7 @@ def __init__(
Transport.__init__(self, loop)
self._stop_requested = False
self._pipe_channel = pipe_channel
self._loop: asyncio.AbstractEventLoop

def request_stop(self) -> None:
self._stop_requested = True
Expand Down
4 changes: 3 additions & 1 deletion playwright/_impl/_network.py
Expand Up @@ -54,6 +54,7 @@
if TYPE_CHECKING: # pragma: no cover
from playwright._impl._fetch import APIResponse
from playwright._impl._frame import Frame
from playwright._impl._page import Page


def serialize_headers(headers: Dict[str, str]) -> HeadersArray:
Expand Down Expand Up @@ -513,6 +514,7 @@ def __init__(
) -> None:
super().__init__(parent, type, guid, initializer)
self._is_closed = False
self._page = cast("Page", parent)
self._channel.on(
"frameSent",
lambda params: self._on_frame_sent(params["opcode"], params["data"]),
Expand Down Expand Up @@ -555,7 +557,7 @@ def expect_event(
wait_helper.reject_on_event(
self, WebSocket.Events.Error, Error("Socket error")
)
wait_helper.reject_on_event(self._parent, "close", Error("Page closed"))
wait_helper.reject_on_event(self._page, "close", Error("Page closed"))
wait_helper.wait_for_event(self, event, predicate)
return EventContextManagerImpl(wait_helper.result())

Expand Down
4 changes: 2 additions & 2 deletions playwright/_impl/_page.py
Expand Up @@ -133,7 +133,7 @@ def __init__(
self, parent: ChannelOwner, type: str, guid: str, initializer: Dict
) -> None:
super().__init__(parent, type, guid, initializer)
self._browser_context: BrowserContext = parent
self._browser_context = cast("BrowserContext", parent)
self.accessibility = Accessibility(self._channel)
self.keyboard = Keyboard(self._channel)
self.mouse = Mouse(self._channel)
Expand Down Expand Up @@ -1268,7 +1268,7 @@ async def call(self, func: Callable) -> None:
)


def trim_url(param: URLMatchRequest) -> Optional[str]:
def trim_url(param: Union[URLMatchRequest, URLMatchResponse]) -> Optional[str]:
if isinstance(param, re.Pattern):
return trim_end(param.pattern)
if isinstance(param, str):
Expand Down
2 changes: 1 addition & 1 deletion playwright/_impl/_playwright.py
Expand Up @@ -64,7 +64,7 @@ def __getitem__(self, value: str) -> "BrowserType":
return self.webkit
raise ValueError("Invalid browser " + value)

def _set_selectors(self, selectors: SelectorsOwner) -> None:
def _set_selectors(self, selectors: Selectors) -> None:
selectors_owner = from_channel(self._initializer["selectors"])
self.selectors._remove_channel(selectors_owner)
self.selectors = selectors
Expand Down
7 changes: 4 additions & 3 deletions playwright/sync_api/_context_manager.py
Expand Up @@ -14,12 +14,12 @@

import asyncio
import sys
from typing import Any, Optional
from typing import Any, Optional, cast

from greenlet import greenlet

from playwright._impl._api_types import Error
from playwright._impl._connection import Connection
from playwright._impl._connection import ChannelOwner, Connection
from playwright._impl._driver import compute_driver_executable
from playwright._impl._object_factory import create_remote_object
from playwright._impl._playwright import Playwright
Expand Down Expand Up @@ -77,7 +77,8 @@ def greenlet_main() -> None:

g_self = greenlet.getcurrent()

def callback_wrapper(playwright_impl: Playwright) -> None:
def callback_wrapper(channel_owner: ChannelOwner) -> None:
playwright_impl = cast(Playwright, channel_owner)
self._playwright = SyncPlaywright(playwright_impl)
g_self.switch()

Expand Down

0 comments on commit 982c703

Please sign in to comment.