Skip to content

Commit dd3d84d

Browse files
authored
chore: update dev deps & fix linter (#224)
1 parent 69caf12 commit dd3d84d

File tree

9 files changed

+27
-27
lines changed

9 files changed

+27
-27
lines changed

pyproject.toml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ dependencies = [
4343
[project.optional-dependencies]
4444
dev = [
4545
"build ~= 1.2.0",
46-
"filelock ~=3.15.1",
46+
"filelock ~= 3.15.0",
4747
"mypy ~= 1.10.0",
4848
"pre-commit ~= 3.5.0",
4949
"pydoc-markdown ~= 4.8.0",
@@ -54,12 +54,12 @@ dev = [
5454
"pytest-timeout ~= 2.3.0",
5555
"pytest-xdist ~= 3.6.0",
5656
"respx ~= 0.21.0",
57-
"ruff ~= 0.4.0",
58-
"setuptools ~= 70.1.0", # setuptools are used by pytest, but not explicitly required
57+
"ruff ~= 0.5.0",
58+
"setuptools ~= 70.3.0", # setuptools are used by pytest, but not explicitly required
5959
"twine ~= 5.1.0",
60-
"types-aiofiles ~= 23.2.0.20240403",
60+
"types-aiofiles ~= 24.1.0.20240626",
6161
"types-colorama ~= 0.4.15.20240311",
62-
"types-psutil ~= 5.9.5.20240516",
62+
"types-psutil ~= 6.0.0.20240621",
6363
]
6464
scrapy = [
6565
"scrapy >= 2.11.0",
@@ -74,7 +74,7 @@ scrapy = [
7474
"Apify Homepage" = "https://apify.com"
7575

7676
[build-system]
77-
requires = ["setuptools ~= 70.1.0", "wheel"]
77+
requires = ["setuptools ~= 70.3.0", "wheel"]
7878
build-backend = "setuptools.build_meta"
7979

8080
[tool.setuptools.packages.find]
@@ -86,6 +86,8 @@ apify = ["py.typed"]
8686

8787
[tool.ruff]
8888
line-length = 150
89+
90+
[tool.ruff.lint]
8991
select = ["ALL"]
9092
ignore = [
9193
"ANN401", # Dynamically typed expressions (typing.Any) are disallowed in {filename}

src/apify/_memory_storage/resource_clients/base_resource_client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def _get_storages_dir(cls: type[BaseResourceClient], memory_storage_client: Memo
5050
@classmethod
5151
@abstractmethod
5252
def _get_storage_client_cache(
53-
cls, # noqa: ANN102 # type annotated cls does not work with Self as a return type
53+
cls,
5454
memory_storage_client: MemoryStorageClient,
5555
) -> list[Self]:
5656
raise NotImplementedError('You must override this method in the subclass!')
@@ -62,7 +62,7 @@ def _to_resource_info(self: BaseResourceClient) -> dict:
6262
@classmethod
6363
@abstractmethod
6464
def _create_from_directory(
65-
cls, # noqa: ANN102 # type annotated cls does not work with Self as a return type
65+
cls,
6666
storage_directory: str,
6767
memory_storage_client: MemoryStorageClient,
6868
id: str | None = None, # noqa: A002
@@ -72,7 +72,7 @@ def _create_from_directory(
7272

7373
@classmethod
7474
def _find_or_create_client_by_id_or_name(
75-
cls, # noqa: ANN102 # type annotated cls does not work with Self as a return type
75+
cls,
7676
memory_storage_client: MemoryStorageClient,
7777
id: str | None = None, # noqa: A002
7878
name: str | None = None,

src/apify/_utils.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,7 @@ def get_memory_usage_bytes() -> int:
208208

209209

210210
def maybe_parse_bool(val: str | None) -> bool:
211-
if val in {'true', 'True', '1'}:
212-
return True
213-
return False
211+
return val in {'true', 'True', '1'}
214212

215213

216214
def maybe_parse_datetime(val: str) -> datetime | str:

src/apify/log.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def _get_extra_fields(self: ActorLogFormatter, record: logging.LogRecord) -> dic
7676
extra_fields: dict[str, Any] = {}
7777
for key, value in record.__dict__.items():
7878
if key not in self.empty_record.__dict__:
79-
extra_fields[key] = value
79+
extra_fields[key] = value # noqa: PERF403
8080

8181
return extra_fields
8282

src/apify/proxy_configuration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ async def _check_access(self: ProxyConfiguration) -> None:
325325
proxy_status_url = f'{self._actor_config.proxy_status_url}/?format=json'
326326

327327
status = None
328-
async with httpx.AsyncClient(proxies=await self.new_url()) as client:
328+
async with httpx.AsyncClient(proxies=await self.new_url(), timeout=10) as client:
329329
for _ in range(2):
330330
try:
331331
response = await client.get(proxy_status_url)

tests/integration/test_actor_api_helpers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,12 +374,12 @@ async def main_server() -> None:
374374
async with Actor:
375375

376376
class WebhookHandler(BaseHTTPRequestHandler):
377-
def do_GET(self) -> None: # noqa: N802, ANN101
377+
def do_GET(self) -> None: # noqa: N802
378378
self.send_response(200)
379379
self.end_headers()
380380
self.wfile.write(bytes('Hello, world!', encoding='utf-8'))
381381

382-
def do_POST(self) -> None: # noqa: N802, ANN101
382+
def do_POST(self) -> None: # noqa: N802
383383
nonlocal webhook_body
384384
content_length = self.headers.get('content-length')
385385
length = int(content_length) if content_length else 0

tests/unit/actor/test_actor_log.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ async def test_actor_log(self: TestActorLog, caplog: pytest.LogCaptureFixture) -
6969
assert caplog.records[7].levelno == logging.ERROR
7070
assert caplog.records[7].message == 'Exception message'
7171
assert caplog.records[7].exc_info is not None
72-
assert caplog.records[7].exc_info[0] == ValueError
72+
assert caplog.records[7].exc_info[0] is ValueError
7373
assert isinstance(caplog.records[7].exc_info[1], ValueError)
7474
assert str(caplog.records[7].exc_info[1]) == 'Dummy ValueError'
7575

@@ -79,7 +79,7 @@ async def test_actor_log(self: TestActorLog, caplog: pytest.LogCaptureFixture) -
7979
assert caplog.records[9].levelno == logging.ERROR
8080
assert caplog.records[9].message == 'Actor failed with an exception'
8181
assert caplog.records[9].exc_info is not None
82-
assert caplog.records[9].exc_info[0] == RuntimeError
82+
assert caplog.records[9].exc_info[0] is RuntimeError
8383
assert isinstance(caplog.records[9].exc_info[1], RuntimeError)
8484
assert str(caplog.records[9].exc_info[1]) == 'Dummy RuntimeError'
8585

tests/unit/memory_storage/resource_clients/test_key_value_store.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ async def test_get_and_set_record(tmp_path: Path, key_value_store_client: KeyVal
178178
assert bytes_record_info['value'].decode('utf-8') == bytes_value.decode('utf-8')
179179

180180
# Test using file descriptor
181-
with open(os.path.join(tmp_path, 'test.json'), 'w+', encoding='utf-8') as f: # noqa: ASYNC101
181+
with open(os.path.join(tmp_path, 'test.json'), 'w+', encoding='utf-8') as f: # noqa: ASYNC230
182182
f.write('Test')
183183
with pytest.raises(NotImplementedError, match='File-like values are not supported in local memory storage'):
184184
await key_value_store_client.set_record('file', f)
@@ -272,11 +272,11 @@ async def test_writes_correct_metadata(memory_storage_client: MemoryStorageClien
272272
assert os.path.exists(item_path)
273273
assert os.path.exists(metadata_path)
274274

275-
with open(item_path, 'rb') as item_file: # noqa: ASYNC101
275+
with open(item_path, 'rb') as item_file: # noqa: ASYNC230
276276
actual_value = maybe_parse_body(item_file.read(), expected_output['contentType'])
277277
assert actual_value == test_input['value']
278278

279-
with open(metadata_path, encoding='utf-8') as metadata_file: # noqa: ASYNC101
279+
with open(metadata_path, encoding='utf-8') as metadata_file: # noqa: ASYNC230
280280
metadata = json.load(metadata_file)
281281
assert metadata['key'] == expected_output['key']
282282
assert expected_output['contentType'] in metadata['contentType']
@@ -364,12 +364,12 @@ async def test_reads_correct_metadata(memory_storage_client: MemoryStorageClient
364364

365365
# Write the store metadata to disk
366366
store_metadata_path = os.path.join(storage_path, '__metadata__.json')
367-
with open(store_metadata_path, mode='wb') as store_metadata_file: # noqa: ASYNC101
367+
with open(store_metadata_path, mode='wb') as store_metadata_file: # noqa: ASYNC230
368368
store_metadata_file.write(json_dumps(store_metadata).encode('utf-8'))
369369

370370
# Write the test input item to the disk
371371
item_path = os.path.join(storage_path, test_input['filename'])
372-
with open(item_path, 'wb') as item_file: # noqa: ASYNC101
372+
with open(item_path, 'wb') as item_file: # noqa: ASYNC230
373373
if isinstance(test_input['value'], bytes):
374374
item_file.write(test_input['value'])
375375
elif isinstance(test_input['value'], str):
@@ -380,7 +380,7 @@ async def test_reads_correct_metadata(memory_storage_client: MemoryStorageClient
380380
# Optionally write the metadata to disk if there is some
381381
if test_input['metadata'] is not None:
382382
metadata_path = os.path.join(storage_path, test_input['filename'] + '.__metadata__.json')
383-
with open(metadata_path, 'w', encoding='utf-8') as metadata_file: # noqa: ASYNC101
383+
with open(metadata_path, 'w', encoding='utf-8') as metadata_file: # noqa: ASYNC230
384384
metadata_file.write(
385385
json_dumps(
386386
{

tests/unit/test_utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ async def test__force_remove(tmp_path: Path) -> None:
177177
assert os.path.exists(test_file_path) is False
178178

179179
# Removes the file if it exists
180-
with open(test_file_path, 'a', encoding='utf-8'): # noqa: ASYNC101
180+
with open(test_file_path, 'a', encoding='utf-8'): # noqa: ASYNC230
181181
pass
182182
assert os.path.exists(test_file_path) is True
183183
await force_remove(test_file_path)
@@ -228,11 +228,11 @@ async def test__force_rename(tmp_path: Path) -> None:
228228
# Will remove dst_dir if it exists (also covers normal case)
229229
# Create the src_dir with a file in it
230230
await mkdir(src_dir)
231-
with open(src_file, 'a', encoding='utf-8'): # noqa: ASYNC101
231+
with open(src_file, 'a', encoding='utf-8'): # noqa: ASYNC230
232232
pass
233233
# Create the dst_dir with a file in it
234234
await mkdir(dst_dir)
235-
with open(dst_file, 'a', encoding='utf-8'): # noqa: ASYNC101
235+
with open(dst_file, 'a', encoding='utf-8'): # noqa: ASYNC230
236236
pass
237237
assert os.path.exists(src_file) is True
238238
assert os.path.exists(dst_file) is True

0 commit comments

Comments
 (0)