Skip to content

Commit 8a8c408

Browse files
authored
Use ruff to detect banned import (#57184)
* Use ruff to detect banned import * Combine rules
1 parent 3c53542 commit 8a8c408

File tree

5 files changed

+4
-98
lines changed

5 files changed

+4
-98
lines changed

.pre-commit-config.yaml

-7
Original file line numberDiff line numberDiff line change
@@ -299,13 +299,6 @@ repos:
299299
files: ^pandas/core/
300300
exclude: ^pandas/core/api\.py$
301301
types: [python]
302-
- id: use-io-common-urlopen
303-
name: Use pandas.io.common.urlopen instead of urllib.request.urlopen
304-
language: python
305-
entry: python scripts/use_io_common_urlopen.py
306-
files: ^pandas/
307-
exclude: ^pandas/tests/
308-
types: [python]
309302
- id: no-bool-in-core-generic
310303
name: Use bool_t instead of bool in pandas/core/generic.py
311304
entry: python scripts/no_bool_in_generic.py

pandas/io/common.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ def urlopen(*args, **kwargs):
286286
"""
287287
import urllib.request
288288

289-
return urllib.request.urlopen(*args, **kwargs)
289+
return urllib.request.urlopen(*args, **kwargs) # noqa: TID251
290290

291291

292292
def is_fsspec_url(url: FilePath | BaseBuffer) -> bool:

pyproject.toml

+3
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,9 @@ exclude = [
330330
"env",
331331
]
332332

333+
[tool.ruff.lint.flake8-tidy-imports.banned-api]
334+
"urllib.request.urlopen".msg = "Use pandas.io.common.urlopen instead of urllib.request.urlopen"
335+
333336
[tool.ruff.per-file-ignores]
334337
# relative imports allowed for asv_bench
335338
"asv_bench/*" = ["TID", "NPY002"]

scripts/tests/test_use_io_common_urlopen.py

-23
This file was deleted.

scripts/use_io_common_urlopen.py

-67
This file was deleted.

0 commit comments

Comments
 (0)