Skip to content

Commit 620d9bc

Browse files
Merge pull request #3181 from VWS-Python/chore/pylint-builtin-bans
Ban dynamic builtins and typing.cast in lint config
2 parents 01d4dfb + 5b6a2e5 commit 620d9bc

4 files changed

Lines changed: 25 additions & 4 deletions

File tree

pyproject.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ lint.per-file-ignores."tests/**" = [
198198
lint.unfixable = [
199199
"ERA001",
200200
]
201+
lint.flake8-tidy-imports.banned-api."typing.cast".msg = "typing.cast is banned: use explicit type narrowing or a typed variable instead."
201202
lint.pydocstyle.convention = "google"
202203

203204
[tool.pylint]
@@ -242,6 +243,17 @@ MASTER.per-file-ignores = [
242243
"docs/source/doccmd_*.py:invalid-name",
243244
"doccmd_README_rst_*.py:invalid-name",
244245
]
246+
DEPRECATED_BUILTINS.bad-functions = [
247+
# Use Pylint until Ruff can ban bare builtin calls, or until custom rules
248+
# make this removable:
249+
# https://github.com/astral-sh/ruff/issues/10079
250+
# https://github.com/astral-sh/ruff/issues/970
251+
"filter",
252+
"getattr",
253+
"hasattr",
254+
"map",
255+
"setattr",
256+
]
245257
# Enable the message, report, category or checker with the given id(s). You can
246258
# either give multiple identifier separated by comma (,) or put this option
247259
# multiple time (only on the command line, not in the configuration file where

src/mock_vws/_requests_mock_server/decorators.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,10 @@ def wrapped(
160160
# req_kwargs is added dynamically by the responses
161161
# library onto PreparedRequest objects - it is not
162162
# in the requests type stubs.
163-
req_kwargs: dict[str, Any] = getattr(request, "req_kwargs", {})
163+
req_kwargs: dict[str, Any] = request.__dict__.get(
164+
"req_kwargs",
165+
{},
166+
)
164167
timeout: tuple[float, float] | float | int | None = req_kwargs.get(
165168
"timeout"
166169
)
@@ -221,7 +224,10 @@ def __enter__(self) -> Self:
221224
compiled_url_pattern = re.compile(pattern=url_pattern)
222225

223226
for http_method in route.http_methods:
224-
original_callback = getattr(api, route.route_name)
227+
original_callback = object.__getattribute__(
228+
api,
229+
route.route_name,
230+
)
225231
mock.add_callback(
226232
method=http_method,
227233
url=compiled_url_pattern,

src/mock_vws/_respx_mock_server/decorators.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,10 @@ def start_respx_router(
161161
compiled_url_pattern = re.compile(pattern=url_pattern)
162162

163163
for http_method in route.http_methods:
164-
original_callback = getattr(api, route.route_name)
164+
original_callback = object.__getattribute__(
165+
api,
166+
route.route_name,
167+
)
165168
router.route(
166169
method=http_method,
167170
url=compiled_url_pattern,

tests/mock_vws/test_target_validators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def test_validate_target_id_exists_uses_correct_path_segment(
7171
"""
7272
database = _database_with_target(target_id=target_id)
7373

74-
monkeypatch.setattr(
74+
monkeypatch.setattr( # pylint: disable=bad-builtin
7575
target=target_validators,
7676
name="get_database_matching_server_keys",
7777
value=partial(_always_match_database, database=database),

0 commit comments

Comments
 (0)