Skip to content

Commit 85df32c

Browse files
authored
chore: filter_none by default (microsoft#2173)
1 parent 8705b35 commit 85df32c

10 files changed

+42
-64
lines changed

playwright/_impl/_browser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from playwright._impl._artifact import Artifact
2828
from playwright._impl._browser_context import BrowserContext
2929
from playwright._impl._cdp_session import CDPSession
30-
from playwright._impl._connection import ChannelOwner, filter_none, from_channel
30+
from playwright._impl._connection import ChannelOwner, from_channel
3131
from playwright._impl._errors import is_target_closed_error
3232
from playwright._impl._helper import (
3333
ColorScheme,
@@ -183,7 +183,7 @@ async def close(self, reason: str = None) -> None:
183183
if self._should_close_connection_on_close:
184184
await self._connection.stop_async()
185185
else:
186-
await self._channel.send("close", filter_none({"reason": reason}))
186+
await self._channel.send("close", {"reason": reason})
187187
except Exception as e:
188188
if not is_target_closed_error(e):
189189
raise e

playwright/_impl/_browser_context.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
from playwright._impl._cdp_session import CDPSession
4141
from playwright._impl._connection import (
4242
ChannelOwner,
43-
filter_none,
4443
from_channel,
4544
from_nullable_channel,
4645
)
@@ -482,7 +481,7 @@ async def _inner_close() -> None:
482481
await har.delete()
483482

484483
await self._channel._connection.wrap_api_call(_inner_close, True)
485-
await self._channel.send("close", filter_none({"reason": reason}))
484+
await self._channel.send("close", {"reason": reason})
486485
await self._closed_future
487486

488487
async def storage_state(self, path: Union[str, Path] = None) -> StorageState:

playwright/_impl/_browser_type.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
from playwright._impl._connection import (
2929
ChannelOwner,
3030
Connection,
31-
filter_none,
3231
from_channel,
3332
from_nullable_channel,
3433
)
@@ -200,15 +199,13 @@ async def connect(
200199
pipe_channel = (
201200
await local_utils._channel.send_return_as_dict(
202201
"connect",
203-
filter_none(
204-
{
205-
"wsEndpoint": ws_endpoint,
206-
"headers": headers,
207-
"slowMo": slow_mo,
208-
"timeout": timeout,
209-
"exposeNetwork": expose_network,
210-
}
211-
),
202+
{
203+
"wsEndpoint": ws_endpoint,
204+
"headers": headers,
205+
"slowMo": slow_mo,
206+
"timeout": timeout,
207+
"exposeNetwork": expose_network,
208+
},
212209
)
213210
)["pipe"]
214211
transport = JsonPipeTransport(self._connection._loop, pipe_channel)

playwright/_impl/_connection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ async def inner_send(
8282
if params is None:
8383
params = {}
8484
callback = self._connection._send_message_to_server(
85-
self._object, method, params
85+
self._object, method, _filter_none(params)
8686
)
8787
if self._connection._error:
8888
error = self._connection._error
@@ -565,7 +565,7 @@ def _extract_stack_trace_information_from_stack(
565565
}
566566

567567

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

571571

playwright/_impl/_element_handle.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,7 @@
1818
from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Union, cast
1919

2020
from playwright._impl._api_structures import FilePayload, FloatRect, Position
21-
from playwright._impl._connection import (
22-
ChannelOwner,
23-
filter_none,
24-
from_nullable_channel,
25-
)
21+
from playwright._impl._connection import ChannelOwner, from_nullable_channel
2622
from playwright._impl._helper import (
2723
Error,
2824
KeyboardModifier,
@@ -202,7 +198,8 @@ async def set_input_files(
202198
await self._channel.send(
203199
"setInputFiles",
204200
{
205-
**filter_none({"timeout": timeout, "noWaitAfter": noWaitAfter}),
201+
"timeout": timeout,
202+
"noWaitAfter": noWaitAfter,
206203
**converted,
207204
},
208205
)
@@ -408,4 +405,4 @@ def convert_select_option_values(
408405
element = [element]
409406
elements = list(map(lambda e: e._channel, element))
410407

411-
return filter_none(dict(options=options, elements=elements))
408+
return dict(options=options, elements=elements)

playwright/_impl/_fetch.py

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
ServerFilePayload,
3030
StorageState,
3131
)
32-
from playwright._impl._connection import ChannelOwner, filter_none, from_channel
32+
from playwright._impl._connection import ChannelOwner, from_channel
3333
from playwright._impl._errors import is_target_closed_error
3434
from playwright._impl._helper import (
3535
Error,
@@ -368,22 +368,20 @@ async def _inner_fetch(
368368

369369
response = await self._channel.send(
370370
"fetch",
371-
filter_none(
372-
{
373-
"url": url,
374-
"params": object_to_array(params),
375-
"method": method,
376-
"headers": serialized_headers,
377-
"postData": post_data,
378-
"jsonData": json_data,
379-
"formData": form_data,
380-
"multipartData": multipart_data,
381-
"timeout": timeout,
382-
"failOnStatusCode": failOnStatusCode,
383-
"ignoreHTTPSErrors": ignoreHTTPSErrors,
384-
"maxRedirects": maxRedirects,
385-
}
386-
),
371+
{
372+
"url": url,
373+
"params": object_to_array(params),
374+
"method": method,
375+
"headers": serialized_headers,
376+
"postData": post_data,
377+
"jsonData": json_data,
378+
"formData": form_data,
379+
"multipartData": multipart_data,
380+
"timeout": timeout,
381+
"failOnStatusCode": failOnStatusCode,
382+
"ignoreHTTPSErrors": ignoreHTTPSErrors,
383+
"maxRedirects": maxRedirects,
384+
},
387385
)
388386
return APIResponse(self, response)
389387

playwright/_impl/_frame.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
from playwright._impl._api_structures import AriaRole, FilePayload, Position
2323
from playwright._impl._connection import (
2424
ChannelOwner,
25-
filter_none,
2625
from_channel,
2726
from_nullable_channel,
2827
)
@@ -694,14 +693,10 @@ async def set_input_files(
694693
await self._channel.send(
695694
"setInputFiles",
696695
{
697-
**filter_none(
698-
{
699-
"selector": selector,
700-
"strict": strict,
701-
"timeout": timeout,
702-
"noWaitAfter": noWaitAfter,
703-
}
704-
),
696+
"selector": selector,
697+
"strict": strict,
698+
"timeout": timeout,
699+
"noWaitAfter": noWaitAfter,
705700
**converted,
706701
},
707702
)

playwright/_impl/_locator.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
FrameExpectResult,
3939
Position,
4040
)
41-
from playwright._impl._connection import filter_none
4241
from playwright._impl._element_handle import ElementHandle
4342
from playwright._impl._helper import (
4443
Error,
@@ -707,7 +706,7 @@ async def _expect(
707706
{
708707
"selector": self._selector,
709708
"expression": expression,
710-
**(filter_none(options)),
709+
**options,
711710
},
712711
)
713712
if result.get("received"):

playwright/_impl/_network.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
)
5252
from playwright._impl._connection import (
5353
ChannelOwner,
54-
filter_none,
5554
from_channel,
5655
from_nullable_channel,
5756
)
@@ -303,12 +302,10 @@ async def abort(self, errorCode: str = None) -> None:
303302
await self._race_with_page_close(
304303
self._channel.send(
305304
"abort",
306-
filter_none(
307-
{
308-
"errorCode": errorCode,
309-
"requestUrl": self.request._initializer["url"],
310-
}
311-
),
305+
{
306+
"errorCode": errorCode,
307+
"requestUrl": self.request._initializer["url"],
308+
},
312309
)
313310
)
314311
self._report_handled(True)

playwright/_impl/_tracing.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,7 @@
1616
from typing import Dict, Optional, Union, cast
1717

1818
from playwright._impl._artifact import Artifact
19-
from playwright._impl._connection import (
20-
ChannelOwner,
21-
filter_none,
22-
from_nullable_channel,
23-
)
19+
from playwright._impl._connection import ChannelOwner, from_nullable_channel
2420
from playwright._impl._helper import locals_to_params
2521

2622

@@ -48,7 +44,7 @@ async def start(
4844
async def _inner_start() -> str:
4945
await self._channel.send("tracingStart", params)
5046
return await self._channel.send(
51-
"tracingStartChunk", filter_none({"title": title, "name": name})
47+
"tracingStartChunk", {"title": title, "name": name}
5248
)
5349

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

0 commit comments

Comments
 (0)