Skip to content

Commit 004a8fb

Browse files
authored
cleanup: use [] and {} instead classes (microsoft#98)
1 parent 365319b commit 004a8fb

File tree

9 files changed

+27
-27
lines changed

9 files changed

+27
-27
lines changed

playwright/browser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def __init__(self, scope: ConnectionScope, guid: str, initializer: Dict) -> None
3737
self._is_connected = True
3838
self._is_closed_or_closing = False
3939

40-
self._contexts: List[BrowserContext] = list()
40+
self._contexts: List[BrowserContext] = []
4141
self._channel.on("close", lambda _: self._on_close())
4242

4343
def _on_close(self) -> None:

playwright/browser_context.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ class BrowserContext(ChannelOwner):
4343

4444
def __init__(self, scope: ConnectionScope, guid: str, initializer: Dict) -> None:
4545
super().__init__(scope, guid, initializer, True)
46-
self._pages: List[Page] = list()
47-
self._routes: List[RouteHandlerEntry] = list()
48-
self._bindings: Dict[str, Any] = dict()
49-
self._pending_wait_for_events: List[PendingWaitEvent] = list()
46+
self._pages: List[Page] = []
47+
self._routes: List[RouteHandlerEntry] = []
48+
self._bindings: Dict[str, Any] = {}
49+
self._pending_wait_for_events: List[PendingWaitEvent] = []
5050
self._timeout_settings = TimeoutSettings(None)
5151
self._browser: Optional["Browser"] = None
5252
self._owner_page: Optional[Page] = None
@@ -106,7 +106,7 @@ async def newPage(self) -> Page:
106106

107107
async def cookies(self, urls: Union[str, List[str]]) -> List[Cookie]:
108108
if urls is None:
109-
urls = list()
109+
urls = []
110110
return await self._channel.send("cookies", dict(urls=urls))
111111

112112
async def addCookies(self, cookies: List[Cookie]) -> None:

playwright/connection.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def __init__(self, scope: "ConnectionScope", guid: str) -> None:
3232

3333
async def send(self, method: str, params: dict = None) -> Any:
3434
if params is None:
35-
params = dict()
35+
params = {}
3636
result = await self._scope.send_message_to_server(self._guid, method, params)
3737
# Protocol now has named return values, assume result is one level deeper unless
3838
# there is explicit ambiguity.
@@ -47,7 +47,7 @@ async def send(self, method: str, params: dict = None) -> Any:
4747

4848
def send_no_reply(self, method: str, params: dict = None) -> None:
4949
if params is None:
50-
params = dict()
50+
params = {}
5151
self._scope.send_message_to_server_no_reply(self._guid, method, params)
5252

5353

@@ -74,8 +74,8 @@ def __init__(
7474
self._connection: "Connection" = connection
7575
self._loop: asyncio.AbstractEventLoop = connection._loop
7676
self._guid: str = guid
77-
self._children: List["ConnectionScope"] = list()
78-
self._objects: Dict[str, ChannelOwner] = dict()
77+
self._children: List["ConnectionScope"] = []
78+
self._objects: Dict[str, ChannelOwner] = {}
7979
self._parent = parent
8080

8181
def create_child(self, guid: str) -> "ConnectionScope":
@@ -138,12 +138,12 @@ def __init__(
138138
) -> None:
139139
self._transport = Transport(input, output, loop)
140140
self._transport.on_message = lambda msg: self._dispatch(msg)
141-
self._waiting_for_object: Dict[str, Any] = dict()
141+
self._waiting_for_object: Dict[str, Any] = {}
142142
self._last_id = 0
143143
self._loop = loop
144-
self._objects: Dict[str, ChannelOwner] = dict()
145-
self._scopes: Dict[str, ConnectionScope] = dict()
146-
self._callbacks: Dict[int, ProtocolCallback] = dict()
144+
self._objects: Dict[str, ChannelOwner] = {}
145+
self._scopes: Dict[str, ConnectionScope] = {}
146+
self._callbacks: Dict[int, ProtocolCallback] = {}
147147
self._root_scope = self.create_scope("", None)
148148
self._object_factory = object_factory
149149

@@ -212,7 +212,7 @@ def _replace_channels_with_guids(self, payload: Any) -> Any:
212212
if isinstance(payload, Channel):
213213
return dict(guid=payload._guid)
214214
if isinstance(payload, dict):
215-
result = dict()
215+
result = {}
216216
for key in payload:
217217
result[key] = self._replace_channels_with_guids(payload[key])
218218
return result
@@ -226,7 +226,7 @@ def _replace_guids_with_channels(self, payload: Any) -> Any:
226226
if isinstance(payload, dict):
227227
if payload.get("guid") in self._objects:
228228
return self._objects[payload["guid"]]._channel
229-
result = dict()
229+
result = {}
230230
for key in payload:
231231
result[key] = self._replace_guids_with_channels(payload[key])
232232
return result

playwright/element_handle.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,10 +227,10 @@ async def evalOnSelectorAll(
227227

228228
def convert_select_option_values(arg: ValuesToSelect) -> Any:
229229
if arg is None:
230-
return dict()
230+
return {}
231231
arg_list = arg if isinstance(arg, list) else [arg]
232232
if not len(arg_list):
233-
return dict()
233+
return {}
234234
if isinstance(arg_list[0], ElementHandle):
235235
element_list = cast(List[ElementHandle], arg_list)
236236
return dict(elements=list(map(lambda e: e._channel, element_list)))

playwright/frame.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def __init__(self, scope: ConnectionScope, guid: str, initializer: Dict) -> None
6464
self._name = initializer["name"]
6565
self._url = initializer["url"]
6666
self._detached = False
67-
self._child_frames: List[Frame] = list()
67+
self._child_frames: List[Frame] = []
6868
self._page: "Page"
6969
self._load_states: Set[str] = set()
7070
self._event_emitter = BaseEventEmitter()

playwright/helper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ def is_function_body(expression: str) -> bool:
211211

212212

213213
def locals_to_params(args: Dict) -> Dict:
214-
copy = dict()
214+
copy = {}
215215
for key in args:
216216
if key == "self":
217217
continue

playwright/js_handle.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def serialize_value(value: Any, handles: List[JSHandle], depth: int) -> Any:
134134

135135

136136
def serialize_argument(arg: Any) -> Any:
137-
handles: List[JSHandle] = list()
137+
handles: List[JSHandle] = []
138138
value = serialize_value(arg, handles, 0)
139139
return dict(value=value, handles=handles)
140140

playwright/network.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ async def abort(self, error_code: str = "failed") -> None:
9999
async def fulfill(
100100
self,
101101
status: int = 200,
102-
headers: Dict[str, str] = dict(),
102+
headers: Dict[str, str] = {},
103103
body: Union[str, bytes] = None,
104104
contentType: str = None,
105105
) -> None:
@@ -120,7 +120,7 @@ async def continue_(
120120
headers: Dict[str, str] = None,
121121
postData: Union[str, bytes] = None,
122122
) -> None:
123-
overrides: ContinueParameters = dict()
123+
overrides: ContinueParameters = {}
124124
if method:
125125
overrides["method"] = method
126126
if headers:

playwright/page.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,10 @@ def __init__(self, scope: ConnectionScope, guid: str, initializer: Dict) -> None
105105
self._frames = [self._main_frame]
106106
self._viewport_size = initializer.get("viewportSize")
107107
self._is_closed = False
108-
self._workers: List[Worker] = list()
109-
self._bindings: Dict[str, Any] = dict()
110-
self._pending_wait_for_events: List[PendingWaitEvent] = list()
111-
self._routes: List[RouteHandlerEntry] = list()
108+
self._workers: List[Worker] = []
109+
self._bindings: Dict[str, Any] = {}
110+
self._pending_wait_for_events: List[PendingWaitEvent] = []
111+
self._routes: List[RouteHandlerEntry] = []
112112
self._owned_context: Optional["BrowserContext"] = None
113113
self._timeout_settings = TimeoutSettings(None)
114114

0 commit comments

Comments
 (0)