Skip to content

Commit a6d2a09

Browse files
committed
ci: fixing mypy issues
1 parent ebcaf2e commit a6d2a09

6 files changed

Lines changed: 40 additions & 77 deletions

File tree

pydoll/browser/firefox/base.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
import tempfile
77
from abc import ABC, abstractmethod
88
from random import randint
9-
from typing import TYPE_CHECKING, Any, Awaitable, Callable, Optional, overload
9+
from typing import Any, Awaitable, Callable, Optional, overload
1010

1111
from pydoll.browser.firefox.tab import FirefoxTab
12+
from pydoll.browser.interfaces import BrowserOptionsManager, Options
1213
from pydoll.browser.managers import BrowserProcessManager, TempDirectoryManager
1314
from pydoll.connection.bidi_connection_handler import BiDiConnectionHandler
1415
from pydoll.exceptions import (
@@ -18,10 +19,6 @@
1819
)
1920
from pydoll.protocol.bidi import browsing_context, script, session
2021

21-
if TYPE_CHECKING:
22-
from pydoll.browser.firefox_options import FirefoxOptions
23-
from pydoll.browser.interfaces import BrowserOptionsManager
24-
2522
logger = logging.getLogger(__name__)
2623

2724

@@ -46,7 +43,7 @@ def __init__(
4643
connection_port: BiDi WebSocket port. Random port (9223-9322) if None.
4744
"""
4845
self._validate_connection_port(connection_port)
49-
self.options: FirefoxOptions = options_manager.initialize_options()
46+
self.options: Options = options_manager.initialize_options()
5047
self._connection_port = connection_port if connection_port else randint(9223, 9322)
5148
self._browser_process_manager = BrowserProcessManager()
5249
self._temp_directory_manager = TempDirectoryManager()
@@ -99,7 +96,7 @@ async def start(self) -> FirefoxTab:
9996
})
10097
await self._hide_automation_signals()
10198

102-
response = await self._connection_handler.execute_command(browsing_context.get_tree())
99+
response: dict = await self._connection_handler.execute_command(browsing_context.get_tree())
103100
contexts = response.get('result', {}).get('contexts', [])
104101
if not contexts:
105102
raise FailedToStartBrowser('No browsing contexts found after start')
@@ -140,7 +137,7 @@ async def new_tab(self, url: str = '') -> FirefoxTab:
140137
New FirefoxTab instance.
141138
"""
142139
logger.info('Creating new Firefox tab')
143-
response = await self._connection_handler.execute_command(browsing_context.create())
140+
response: dict = await self._connection_handler.execute_command(browsing_context.create())
144141
context_id = response['result']['context']
145142
tab = FirefoxTab(context_id, self._connection_handler)
146143
self._tabs[context_id] = tab
@@ -155,7 +152,7 @@ async def get_opened_tabs(self) -> list[FirefoxTab]:
155152
Returns:
156153
List of FirefoxTab instances.
157154
"""
158-
response = await self._connection_handler.execute_command(browsing_context.get_tree())
155+
response: dict = await self._connection_handler.execute_command(browsing_context.get_tree())
159156
contexts = response.get('result', {}).get('contexts', [])
160157
tabs = []
161158
for ctx in contexts:
@@ -345,14 +342,11 @@ def _write_user_js(profile_dir: str) -> None:
345342
('marionette.enabled', False),
346343
('toolkit.legacyUserProfileCustomizations.stylesheets', True),
347344
('devtools.debugger.prompt-connection', False),
348-
# Disable automation/testing-specific UI and features
349345
('browser.aboutConfig.showWarning', False),
350346
('browser.shell.checkDefaultBrowser', False),
351347
('browser.startup.homepage_override.mstone', 'ignore'),
352-
# Reduce fingerprinting surface without breaking functionality
353348
('privacy.resistFingerprinting', False),
354349
('privacy.trackingprotection.enabled', False),
355-
# Suppress first-run dialogs and telemetry
356350
('datareporting.healthreport.uploadEnabled', False),
357351
('datareporting.policy.dataSubmissionEnabled', False),
358352
('toolkit.telemetry.enabled', False),

pydoll/browser/firefox/element.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
logger = logging.getLogger(__name__)
1313

14-
# WebDriver special key values (Unicode private use area)
1514
KEYS = {
1615
'ctrl': '\ue009',
1716
'shift': '\ue008',
@@ -211,7 +210,7 @@ async def inner_html(self) -> str:
211210

212211
async def _call_function(self, function_declaration: str) -> Any:
213212
"""Call a JS function with this element as the first argument."""
214-
response = await self._connection_handler.execute_command(
213+
response: dict = await self._connection_handler.execute_command(
215214
script.call_function(
216215
function_declaration=function_declaration,
217216
context=self._context_id,

pydoll/browser/firefox/firefox.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,6 @@ def _get_default_binary_location() -> str:
5151
r'C:\Program Files (x86)\Mozilla Firefox\firefox.exe',
5252
],
5353
'Linux': [
54-
# Prefer the real snap binary over the wrapper scripts —
55-
# the wrappers (/usr/bin/firefox, /snap/bin/firefox) silently
56-
# drop unknown flags like --remote-debugging-port.
5754
'/snap/firefox/current/usr/lib/firefox/firefox',
5855
'/usr/lib/firefox/firefox',
5956
'/usr/bin/firefox-esr',

pydoll/browser/firefox/tab.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from pydoll.browser.firefox.element import KEYS, FirefoxElement
99
from pydoll.protocol.bidi import browsing_context, network, script, session, storage
1010
from pydoll.protocol.bidi import input as bidi_input
11-
from pydoll.protocol.bidi.network import InterceptPhase, NetworkEvent
11+
from pydoll.protocol.bidi.network import Header, InterceptPhase, NetworkEvent
1212

1313
if TYPE_CHECKING:
1414
from pydoll.connection.bidi_connection_handler import BiDiConnectionHandler
@@ -54,7 +54,7 @@ async def go_to(self, url: str, wait: str = 'complete') -> dict:
5454
Navigation result dict with 'url' key.
5555
"""
5656
logger.info(f'Navigating to {url} (context={self._context_id})')
57-
response = await self._connection_handler.execute_command(
57+
response: dict = await self._connection_handler.execute_command(
5858
browsing_context.navigate(self._context_id, url, wait)
5959
)
6060
return response['result']
@@ -71,7 +71,7 @@ async def evaluate(self, expression: str, await_promise: bool = True) -> Any:
7171
The JavaScript result value.
7272
"""
7373
logger.debug(f'Evaluating expression in context={self._context_id}')
74-
response = await self._connection_handler.execute_command(
74+
response: dict = await self._connection_handler.execute_command(
7575
script.evaluate(expression, self._context_id, await_promise)
7676
)
7777
result = response.get('result', {})
@@ -100,7 +100,7 @@ async def find(
100100
f'Finding nodes: selector={selector!r}, type={selector_type}, '
101101
f'context={self._context_id}'
102102
)
103-
response = await self._connection_handler.execute_command(
103+
response: dict = await self._connection_handler.execute_command(
104104
browsing_context.locate_nodes(self._context_id, locator, max_node_count)
105105
)
106106
nodes = response.get('result', {}).get('nodes', [])
@@ -114,7 +114,7 @@ async def take_screenshot(self) -> bytes:
114114
PNG screenshot as bytes.
115115
"""
116116
logger.debug(f'Taking screenshot: context={self._context_id}')
117-
response = await self._connection_handler.execute_command(
117+
response: dict = await self._connection_handler.execute_command(
118118
browsing_context.capture_screenshot(self._context_id)
119119
)
120120
data = response.get('result', {}).get('data', '')
@@ -209,7 +209,7 @@ async def get_cookies(self) -> list[dict]:
209209
httpOnly, secure, sameSite, expiry, etc.
210210
"""
211211
logger.debug(f'Getting cookies: context={self._context_id}')
212-
response = await self._connection_handler.execute_command(
212+
response: dict = await self._connection_handler.execute_command(
213213
storage.get_cookies(self._context_id)
214214
)
215215
return response.get('result', {}).get('cookies', [])
@@ -314,7 +314,7 @@ async def refresh(self, wait: str = 'complete') -> dict:
314314
Reload result dict with 'url' key.
315315
"""
316316
logger.info(f'Refreshing context={self._context_id}')
317-
response = await self._connection_handler.execute_command(
317+
response: dict = await self._connection_handler.execute_command(
318318
browsing_context.reload(self._context_id, wait)
319319
)
320320
return response.get('result', {})
@@ -327,7 +327,7 @@ async def go_back(self) -> dict:
327327
TraverseHistory result dict.
328328
"""
329329
logger.info(f'Going back: context={self._context_id}')
330-
response = await self._connection_handler.execute_command(
330+
response: dict = await self._connection_handler.execute_command(
331331
browsing_context.traverse_history(self._context_id, delta=-1)
332332
)
333333
return response.get('result', {})
@@ -340,7 +340,7 @@ async def go_forward(self) -> dict:
340340
TraverseHistory result dict.
341341
"""
342342
logger.info(f'Going forward: context={self._context_id}')
343-
response = await self._connection_handler.execute_command(
343+
response: dict = await self._connection_handler.execute_command(
344344
browsing_context.traverse_history(self._context_id, delta=1)
345345
)
346346
return response.get('result', {})
@@ -388,7 +388,7 @@ async def add_intercept(
388388
if phases is None:
389389
phases = [InterceptPhase.BEFORE_REQUEST_SENT]
390390
logger.info(f'Adding intercept phases={phases}: context={self._context_id}')
391-
response = await self._connection_handler.execute_command(
391+
response: dict = await self._connection_handler.execute_command(
392392
network.add_intercept(
393393
phases=phases,
394394
contexts=[self._context_id],
@@ -407,7 +407,7 @@ async def continue_request(
407407
request_id: str,
408408
url: Optional[str] = None,
409409
method: Optional[str] = None,
410-
headers: Optional[list[dict]] = None,
410+
headers: Optional[list[Header]] = None,
411411
body: Optional[str] = None,
412412
) -> None:
413413
"""
@@ -440,7 +440,7 @@ async def provide_response(
440440
self,
441441
request_id: str,
442442
status_code: int = 200,
443-
headers: Optional[list[dict]] = None,
443+
headers: Optional[list[Header]] = None,
444444
body: Optional[str] = None,
445445
reason_phrase: Optional[str] = None,
446446
) -> None:
@@ -468,7 +468,7 @@ async def continue_response(
468468
self,
469469
request_id: str,
470470
status_code: Optional[int] = None,
471-
headers: Optional[list[dict]] = None,
471+
headers: Optional[list[Header]] = None,
472472
reason_phrase: Optional[str] = None,
473473
) -> None:
474474
"""
@@ -526,7 +526,7 @@ async def new_tab(self, url: str = '') -> FirefoxTab:
526526
New FirefoxTab instance.
527527
"""
528528
logger.info('Creating new tab')
529-
response = await self._connection_handler.execute_command(browsing_context.create())
529+
response: dict = await self._connection_handler.execute_command(browsing_context.create())
530530
context_id = response['result']['context']
531531
tab = FirefoxTab(context_id, self._connection_handler)
532532
if url:

pydoll/connection/bidi_connection_handler.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
import logging
4-
from typing import TYPE_CHECKING, Optional
4+
from typing import TYPE_CHECKING, Any, Optional
55

66
from pydoll.connection.connection_handler import ConnectionHandler
77
from pydoll.exceptions import BiDiCommandError
@@ -43,7 +43,7 @@ async def execute_command(
4343
Raises:
4444
BiDiCommandError: If the browser returns a BiDi error response.
4545
"""
46-
response = await super().execute_command(command, timeout)
46+
response: Any = await super().execute_command(command, timeout)
4747
if response.get('type') == 'error':
4848
error = response.get('error', 'unknown')
4949
message = response.get('message', '')
@@ -64,7 +64,7 @@ async def new_session(self, capabilities: Optional[dict] = None) -> dict:
6464
Full response dict from the browser.
6565
"""
6666
command = session_module.new_session(capabilities)
67-
response = await self.execute_command(command)
67+
response: dict = await self.execute_command(command)
6868
self._session_id = response.get('result', {}).get('sessionId')
6969
logger.info(f'BiDi session established: sessionId={self._session_id}')
7070
return response

pydoll/protocol/bidi/network.py

Lines changed: 16 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66

77
from pydoll.protocol.base import Command, EmptyResponse, Response
88

9-
# ---------------------------------------------------------------------------
10-
# Shared types
11-
# ---------------------------------------------------------------------------
9+
10+
class BytesValue(TypedDict):
11+
type: str
12+
value: str
1213

1314

1415
class Header(TypedDict):
@@ -22,26 +23,16 @@ def make_header(name: str, value: str) -> Header:
2223

2324

2425
class UrlPatternString(TypedDict):
25-
type: str # 'string'
26+
type: str
2627
pattern: str
2728

2829

29-
class BytesValue(TypedDict):
30-
type: str # 'string' | 'base64'
31-
value: str
32-
33-
3430
class AuthCredentials(TypedDict):
35-
type: str # 'password'
31+
type: str
3632
username: str
3733
password: str
3834

3935

40-
# ---------------------------------------------------------------------------
41-
# Command params
42-
# ---------------------------------------------------------------------------
43-
44-
4536
class AddInterceptParams(TypedDict):
4637
phases: list[str]
4738
contexts: NotRequired[list[str]]
@@ -69,7 +60,7 @@ class ContinueResponseParams(TypedDict):
6960

7061
class ContinueWithAuthParams(TypedDict):
7162
request: str
72-
action: str # 'provideCredentials' | 'default' | 'cancel'
63+
action: str
7364
credentials: NotRequired[AuthCredentials]
7465

7566

@@ -85,19 +76,10 @@ class ProvideResponseParams(TypedDict):
8576
statusCode: NotRequired[int]
8677

8778

88-
# ---------------------------------------------------------------------------
89-
# Result types
90-
# ---------------------------------------------------------------------------
91-
92-
9379
class AddInterceptResult(TypedDict):
9480
intercept: str
9581

9682

97-
# ---------------------------------------------------------------------------
98-
# Response / Command aliases
99-
# ---------------------------------------------------------------------------
100-
10183
AddInterceptResponse = Response[AddInterceptResult]
10284
RemoveInterceptResponse = Response[EmptyResponse]
10385
ContinueRequestResponse = Response[EmptyResponse]
@@ -115,11 +97,6 @@ class AddInterceptResult(TypedDict):
11597
ProvideResponseCommand = Command[ProvideResponseParams, ProvideResponseResponse]
11698

11799

118-
# ---------------------------------------------------------------------------
119-
# Event name constants
120-
# ---------------------------------------------------------------------------
121-
122-
123100
class NetworkEvent:
124101
"""BiDi network event name constants."""
125102

@@ -138,22 +115,14 @@ class NetworkEvent:
138115
]
139116

140117

141-
# ---------------------------------------------------------------------------
142-
# Intercept phases
143-
# ---------------------------------------------------------------------------
144-
145-
146118
class InterceptPhase:
119+
"""BiDi network intercept phase constants."""
120+
147121
BEFORE_REQUEST_SENT = 'beforeRequestSent'
148122
RESPONSE_STARTED = 'responseStarted'
149123
AUTH_REQUIRED = 'authRequired'
150124

151125

152-
# ---------------------------------------------------------------------------
153-
# Factory functions
154-
# ---------------------------------------------------------------------------
155-
156-
157126
def add_intercept(
158127
phases: list[str],
159128
contexts: Optional[list[str]] = None,
@@ -163,9 +132,9 @@ def add_intercept(
163132
Register a network intercept.
164133
165134
Args:
166-
phases: List of phases to intercept. Use ``InterceptPhase`` constants.
167-
contexts: Browsing context IDs to scope the intercept to (tab-level).
168-
url_patterns: Optional URL glob patterns to match (e.g. '*://example.com/*').
135+
phases: Phases to intercept. Use ``InterceptPhase`` constants.
136+
contexts: Browsing context IDs to scope the intercept to.
137+
url_patterns: URL patterns to match (must be valid URL pattern strings).
169138
170139
Returns:
171140
Command dict for ``network.addIntercept``.
@@ -226,6 +195,10 @@ def continue_with_auth(
226195
username: Optional[str] = None,
227196
password: Optional[str] = None,
228197
) -> ContinueWithAuthCommand:
198+
"""
199+
Args:
200+
action: ``'provideCredentials'``, ``'default'``, or ``'cancel'``.
201+
"""
229202
params = ContinueWithAuthParams(request=request_id, action=action)
230203
if action == 'provideCredentials' and username is not None and password is not None:
231204
params['credentials'] = AuthCredentials(

0 commit comments

Comments
 (0)