Skip to content

Commit bb8bc8f

Browse files
committed
Use ruff to detect banned import
1 parent b51c38a commit bb8bc8f

File tree

5 files changed

+8
-98
lines changed

5 files changed

+8
-98
lines changed

.pre-commit-config.yaml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ repos:
3030
files: ^pandas
3131
exclude: ^pandas/tests
3232
args: [--select, "ANN001,ANN2", --fix-only, --exit-non-zero-on-fix]
33+
- id: ruff
34+
args: [--exit-non-zero-on-fix, --select=TID251]
35+
files: ^pandas/
36+
exclude: ^pandas/tests/
3337
- id: ruff-format
3438
# TODO: "." not needed in ruff 0.1.8
3539
args: ["."]
@@ -299,13 +303,6 @@ repos:
299303
files: ^pandas/core/
300304
exclude: ^pandas/core/api\.py$
301305
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]
309306
- id: no-bool-in-core-generic
310307
name: Use bool_t instead of bool in pandas/core/generic.py
311308
entry: python scripts/no_bool_in_generic.py

pandas/io/common.py

Lines changed: 1 addition & 1 deletion
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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 0 additions & 23 deletions
This file was deleted.

scripts/use_io_common_urlopen.py

Lines changed: 0 additions & 67 deletions
This file was deleted.

0 commit comments

Comments
 (0)