Skip to content

Commit 0a4c65b

Browse files
authored
chore: Use specific rule codes when ignoring type issues (#345)
- Rm ignore of `PGH003` rule and update type ignores to be specific. - Rm the comment about deps in the pyprojtoml, as it is obvious now probably.
1 parent a0070b6 commit 0a4c65b

File tree

7 files changed

+17
-18
lines changed

7 files changed

+17
-18
lines changed

pyproject.toml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@ keywords = [
4141
"Issue Tracker" = "https://github.com/apify/apify-sdk-python/issues"
4242
"Repository" = "https://github.com/apify/apify-sdk-python"
4343

44-
# We use inclusive ordered comparison clauses for external packages intentionally in order to enhance SDK's
45-
# compatibility with external packages. This decision was discussed in detail in the following PR:
46-
# https://github.com/apify/apify-sdk-python/pull/154.
4744
[tool.poetry.dependencies]
4845
python = "^3.9"
4946
apify-client = ">=1.8.1"
@@ -94,7 +91,6 @@ ignore = [
9491
"G004", # Logging statement uses f-string
9592
"ISC001", # This rule may cause conflicts when used with the formatter
9693
"FIX", # flake8-fixme
97-
"PGH003", # Use specific rule codes when ignoring type issues
9894
"PLR0911", # Too many return statements
9995
"PLR0913", # Too many arguments in function definition
10096
"PLR0915", # Too many statements
@@ -184,15 +180,17 @@ exclude = []
184180
module = ['scrapy', 'scrapy.*', 'lazy_object_proxy']
185181
ignore_missing_imports = true
186182

183+
[tool.basedpyright]
184+
pythonVersion = "3.9"
185+
typeCheckingMode = "standard"
186+
include = ["src", "tests"]
187+
187188
[tool.coverage.report]
188189
exclude_lines = [
189190
"pragma: no cover",
190191
"if TYPE_CHECKING:",
191192
"assert_never()",
192193
]
193194

194-
[tool.basedpyright]
195-
typeCheckingMode = "standard"
196-
197195
[tool.ipdb]
198196
context = 7

src/apify/_configuration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,4 +323,4 @@ class Configuration(CrawleeConfiguration):
323323

324324

325325
# Monkey-patch the base class so that it works with the extended configuration
326-
CrawleeConfiguration.get_global_configuration = Configuration.get_global_configuration # type: ignore
326+
CrawleeConfiguration.get_global_configuration = Configuration.get_global_configuration # type: ignore[method-assign]

tests/integration/test_actor_events.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ async def test_event_listener_can_be_removed_successfully(
7777
) -> None:
7878
async def main() -> None:
7979
import os
80+
from typing import Any
8081

8182
from apify_shared.consts import ApifyEnvVars
8283
from crawlee.events._types import Event
@@ -85,7 +86,7 @@ async def main() -> None:
8586

8687
counter = 0
8788

88-
def count_event(data): # type: ignore # noqa: ANN202, ANN001
89+
def count_event(data: Any) -> None:
8990
nonlocal counter
9091
print(data)
9192
counter += 1

tests/unit/actor/test_actor_create_proxy_configuration.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ async def test_basic_proxy_configuration_creation(
5757
assert proxy_configuration._password == DUMMY_PASSWORD
5858
assert proxy_configuration._country_code == country_code
5959

60-
assert len(patched_apify_client.calls['user']['get']) == 1 # type: ignore
60+
assert len(patched_apify_client.calls['user']['get']) == 1 # type: ignore[attr-defined]
6161
assert len(route.calls) == 1
6262

6363
await Actor.exit()
@@ -137,7 +137,7 @@ async def test_proxy_configuration_with_actor_proxy_input(
137137
== f'http://groups-{"+".join(groups)},country-{country_code}:{DUMMY_PASSWORD}@proxy.apify.com:8000'
138138
)
139139

140-
assert len(patched_apify_client.calls['user']['get']) == 2 # type: ignore
140+
assert len(patched_apify_client.calls['user']['get']) == 2 # type: ignore[attr-defined]
141141
assert len(route.calls) == 2
142142

143143
await Actor.exit()

tests/unit/actor/test_actor_env_helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ async def test_get_env_with_randomized_env_vars(monkeypatch: pytest.MonkeyPatch)
9797
continue
9898

9999
datetime_get_env_var = datetime_env_var.name.lower()
100-
expected_get_env[datetime_get_env_var] = datetime.now(TzInfo(0)) # type: ignore
100+
expected_get_env[datetime_get_env_var] = datetime.now(TzInfo(0)) # type: ignore[call-arg]
101101
monkeypatch.setenv(
102102
datetime_env_var,
103103
expected_get_env[datetime_get_env_var].strftime('%Y-%m-%dT%H:%M:%S.%fZ'),

tests/unit/scrapy/middlewares/test_apify_proxy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,5 +150,5 @@ def test_handles_exceptions(
150150
dummy_request: Request,
151151
exception: Exception,
152152
) -> None:
153-
returned_value = middleware.process_exception(dummy_request, exception, spider) # type: ignore
153+
returned_value = middleware.process_exception(dummy_request, exception, spider) # type: ignore[func-returns-value]
154154
assert returned_value is None

tests/unit/test_proxy_configuration.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@ def test_invalid_arguments() -> None:
7474
(['abc', 'DEF', 'geh$'], 2),
7575
([111, 'DEF', 'geh$'], 2),
7676
]:
77-
with pytest.raises(ValueError, match=re.escape(str(invalid_groups[bad_group_index]))): # type: ignore
78-
ProxyConfiguration(groups=invalid_groups) # type: ignore
77+
with pytest.raises(ValueError, match=re.escape(str(invalid_groups[bad_group_index]))): # type: ignore[index]
78+
ProxyConfiguration(groups=invalid_groups) # type: ignore[arg-type]
7979

8080
for invalid_country_code in ['CZE', 'aa', 'DDDD', 1111]:
8181
with pytest.raises(ValueError, match=re.escape(str(invalid_country_code))):
82-
ProxyConfiguration(country_code=invalid_country_code) # type: ignore
82+
ProxyConfiguration(country_code=invalid_country_code) # type: ignore[arg-type]
8383

8484
with pytest.raises(ValueError, match='Exactly one of .* must be specified'):
8585
ProxyConfiguration(
@@ -402,7 +402,7 @@ async def test_initialize_with_valid_configuration(
402402
assert proxy_configuration._password == DUMMY_PASSWORD
403403
assert proxy_configuration.is_man_in_the_middle is True
404404

405-
assert len(patched_apify_client.calls['user']['get']) == 1 # type: ignore
405+
assert len(patched_apify_client.calls['user']['get']) == 1 # type: ignore[attr-defined]
406406
assert len(route.calls) == 1
407407

408408

@@ -526,7 +526,7 @@ async def test_initialize_with_non_apify_proxy(
526526

527527
await proxy_configuration.initialize()
528528

529-
assert len(patched_apify_client.calls['user']['get']) == 0 # type: ignore
529+
assert len(patched_apify_client.calls['user']['get']) == 0 # type: ignore[attr-defined]
530530
assert len(route.calls) == 0
531531

532532

0 commit comments

Comments
 (0)