Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: filter_none by default #2173

Merged
merged 1 commit into from
Nov 27, 2023
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
4 changes: 2 additions & 2 deletions playwright/_impl/_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from playwright._impl._artifact import Artifact
from playwright._impl._browser_context import BrowserContext
from playwright._impl._cdp_session import CDPSession
from playwright._impl._connection import ChannelOwner, filter_none, from_channel
from playwright._impl._connection import ChannelOwner, from_channel
from playwright._impl._errors import is_target_closed_error
from playwright._impl._helper import (
ColorScheme,
Expand Down Expand Up @@ -183,7 +183,7 @@ async def close(self, reason: str = None) -> None:
if self._should_close_connection_on_close:
await self._connection.stop_async()
else:
await self._channel.send("close", filter_none({"reason": reason}))
await self._channel.send("close", {"reason": reason})
except Exception as e:
if not is_target_closed_error(e):
raise e
Expand Down
3 changes: 1 addition & 2 deletions playwright/_impl/_browser_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
from playwright._impl._cdp_session import CDPSession
from playwright._impl._connection import (
ChannelOwner,
filter_none,
from_channel,
from_nullable_channel,
)
Expand Down Expand Up @@ -482,7 +481,7 @@ async def _inner_close() -> None:
await har.delete()

await self._channel._connection.wrap_api_call(_inner_close, True)
await self._channel.send("close", filter_none({"reason": reason}))
await self._channel.send("close", {"reason": reason})
await self._closed_future

async def storage_state(self, path: Union[str, Path] = None) -> StorageState:
Expand Down
17 changes: 7 additions & 10 deletions playwright/_impl/_browser_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
from playwright._impl._connection import (
ChannelOwner,
Connection,
filter_none,
from_channel,
from_nullable_channel,
)
Expand Down Expand Up @@ -200,15 +199,13 @@ async def connect(
pipe_channel = (
await local_utils._channel.send_return_as_dict(
"connect",
filter_none(
{
"wsEndpoint": ws_endpoint,
"headers": headers,
"slowMo": slow_mo,
"timeout": timeout,
"exposeNetwork": expose_network,
}
),
{
"wsEndpoint": ws_endpoint,
"headers": headers,
"slowMo": slow_mo,
"timeout": timeout,
"exposeNetwork": expose_network,
},
)
)["pipe"]
transport = JsonPipeTransport(self._connection._loop, pipe_channel)
Expand Down
4 changes: 2 additions & 2 deletions playwright/_impl/_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ async def inner_send(
if params is None:
params = {}
callback = self._connection._send_message_to_server(
self._object, method, params
self._object, method, _filter_none(params)
)
if self._connection._error:
error = self._connection._error
Expand Down Expand Up @@ -565,7 +565,7 @@ def _extract_stack_trace_information_from_stack(
}


def filter_none(d: Mapping) -> Dict:
def _filter_none(d: Mapping) -> Dict:
return {k: v for k, v in d.items() if v is not None}


Expand Down
11 changes: 4 additions & 7 deletions playwright/_impl/_element_handle.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@
from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Union, cast

from playwright._impl._api_structures import FilePayload, FloatRect, Position
from playwright._impl._connection import (
ChannelOwner,
filter_none,
from_nullable_channel,
)
from playwright._impl._connection import ChannelOwner, from_nullable_channel
from playwright._impl._helper import (
Error,
KeyboardModifier,
Expand Down Expand Up @@ -202,7 +198,8 @@ async def set_input_files(
await self._channel.send(
"setInputFiles",
{
**filter_none({"timeout": timeout, "noWaitAfter": noWaitAfter}),
"timeout": timeout,
"noWaitAfter": noWaitAfter,
**converted,
},
)
Expand Down Expand Up @@ -408,4 +405,4 @@ def convert_select_option_values(
element = [element]
elements = list(map(lambda e: e._channel, element))

return filter_none(dict(options=options, elements=elements))
return dict(options=options, elements=elements)
32 changes: 15 additions & 17 deletions playwright/_impl/_fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
ServerFilePayload,
StorageState,
)
from playwright._impl._connection import ChannelOwner, filter_none, from_channel
from playwright._impl._connection import ChannelOwner, from_channel
from playwright._impl._errors import is_target_closed_error
from playwright._impl._helper import (
Error,
Expand Down Expand Up @@ -368,22 +368,20 @@ async def _inner_fetch(

response = await self._channel.send(
"fetch",
filter_none(
{
"url": url,
"params": object_to_array(params),
"method": method,
"headers": serialized_headers,
"postData": post_data,
"jsonData": json_data,
"formData": form_data,
"multipartData": multipart_data,
"timeout": timeout,
"failOnStatusCode": failOnStatusCode,
"ignoreHTTPSErrors": ignoreHTTPSErrors,
"maxRedirects": maxRedirects,
}
),
{
"url": url,
"params": object_to_array(params),
"method": method,
"headers": serialized_headers,
"postData": post_data,
"jsonData": json_data,
"formData": form_data,
"multipartData": multipart_data,
"timeout": timeout,
"failOnStatusCode": failOnStatusCode,
"ignoreHTTPSErrors": ignoreHTTPSErrors,
"maxRedirects": maxRedirects,
},
)
return APIResponse(self, response)

Expand Down
13 changes: 4 additions & 9 deletions playwright/_impl/_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
from playwright._impl._api_structures import AriaRole, FilePayload, Position
from playwright._impl._connection import (
ChannelOwner,
filter_none,
from_channel,
from_nullable_channel,
)
Expand Down Expand Up @@ -694,14 +693,10 @@ async def set_input_files(
await self._channel.send(
"setInputFiles",
{
**filter_none(
{
"selector": selector,
"strict": strict,
"timeout": timeout,
"noWaitAfter": noWaitAfter,
}
),
"selector": selector,
"strict": strict,
"timeout": timeout,
"noWaitAfter": noWaitAfter,
**converted,
},
)
Expand Down
3 changes: 1 addition & 2 deletions playwright/_impl/_locator.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
FrameExpectResult,
Position,
)
from playwright._impl._connection import filter_none
from playwright._impl._element_handle import ElementHandle
from playwright._impl._helper import (
Error,
Expand Down Expand Up @@ -707,7 +706,7 @@ async def _expect(
{
"selector": self._selector,
"expression": expression,
**(filter_none(options)),
**options,
},
)
if result.get("received"):
Expand Down
11 changes: 4 additions & 7 deletions playwright/_impl/_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
)
from playwright._impl._connection import (
ChannelOwner,
filter_none,
from_channel,
from_nullable_channel,
)
Expand Down Expand Up @@ -303,12 +302,10 @@ async def abort(self, errorCode: str = None) -> None:
await self._race_with_page_close(
self._channel.send(
"abort",
filter_none(
{
"errorCode": errorCode,
"requestUrl": self.request._initializer["url"],
}
),
{
"errorCode": errorCode,
"requestUrl": self.request._initializer["url"],
},
)
)
self._report_handled(True)
Expand Down
8 changes: 2 additions & 6 deletions playwright/_impl/_tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@
from typing import Dict, Optional, Union, cast

from playwright._impl._artifact import Artifact
from playwright._impl._connection import (
ChannelOwner,
filter_none,
from_nullable_channel,
)
from playwright._impl._connection import ChannelOwner, from_nullable_channel
from playwright._impl._helper import locals_to_params


Expand Down Expand Up @@ -48,7 +44,7 @@ async def start(
async def _inner_start() -> str:
await self._channel.send("tracingStart", params)
return await self._channel.send(
"tracingStartChunk", filter_none({"title": title, "name": name})
"tracingStartChunk", {"title": title, "name": name}
)

trace_name = await self._connection.wrap_api_call(_inner_start, True)
Expand Down