Skip to content

Commit c81b136

Browse files
committed
chore(internal): enable more lint rules (#93)
1 parent 1cae8ed commit c81b136

File tree

9 files changed

+35
-22
lines changed

9 files changed

+35
-22
lines changed

pyproject.toml

+20-11
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,18 @@ Repository = "https://github.com/orbcorp/orb-python"
4545

4646
[tool.rye]
4747
managed = true
48+
# version pins are in requirements-dev.lock
4849
dev-dependencies = [
49-
"pyright==1.1.332",
50-
"mypy==1.7.1",
51-
"black==23.3.0",
52-
"respx==0.20.2",
53-
"pytest==7.1.1",
54-
"pytest-asyncio==0.21.1",
55-
"ruff==0.0.282",
56-
"isort==5.10.1",
57-
"time-machine==2.9.0",
58-
"nox==2023.4.22",
50+
"pyright",
51+
"mypy",
52+
"black",
53+
"respx",
54+
"pytest",
55+
"pytest-asyncio",
56+
"ruff",
57+
"isort",
58+
"time-machine",
59+
"nox",
5960
"dirty-equals>=0.6.0",
6061

6162
]
@@ -132,9 +133,11 @@ extra_standard_library = ["typing_extensions"]
132133

133134
[tool.ruff]
134135
line-length = 120
135-
format = "grouped"
136+
output-format = "grouped"
136137
target-version = "py37"
137138
select = [
139+
# bugbear rules
140+
"B",
138141
# remove unused imports
139142
"F401",
140143
# bare except statements
@@ -145,6 +148,12 @@ select = [
145148
"T201",
146149
"T203",
147150
]
151+
ignore = [
152+
# lru_cache in methods, will be fixed separately
153+
"B019",
154+
# mutable defaults
155+
"B006",
156+
]
148157
unfixable = [
149158
# disable auto fix for print statements
150159
"T201",

requirements-dev.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pytest-asyncio==0.21.1
4343
python-dateutil==2.8.2
4444
pytz==2023.3.post1
4545
respx==0.20.2
46-
ruff==0.0.282
46+
ruff==0.1.7
4747
six==1.16.0
4848
sniffio==1.3.0
4949
time-machine==2.9.0

src/orb/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999
for __name in __all__:
100100
if not __name.startswith("__"):
101101
try:
102-
setattr(__locals[__name], "__module__", "orb")
102+
__locals[__name].__module__ = "orb"
103103
except (TypeError, AttributeError):
104104
# Some of our exported symbols are builtins which we can't set attributes for.
105105
pass

src/orb/_streaming.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def __stream__(self) -> Iterator[ResponseT]:
5151
yield process_data(data=sse.json(), cast_to=cast_to, response=response)
5252

5353
# Ensure the entire stream is consumed
54-
for sse in iterator:
54+
for _sse in iterator:
5555
...
5656

5757

@@ -94,7 +94,7 @@ async def __stream__(self) -> AsyncIterator[ResponseT]:
9494
yield process_data(data=sse.json(), cast_to=cast_to, response=response)
9595

9696
# Ensure the entire stream is consumed
97-
async for sse in iterator:
97+
async for _sse in iterator:
9898
...
9999

100100

src/orb/_types.py

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444

4545

4646
class BinaryResponseContent(ABC):
47+
@abstractmethod
4748
def __init__(
4849
self,
4950
response: Any,

src/orb/_utils/_utils.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,8 @@ def extract_type_arg(typ: type, index: int) -> type:
194194
args = get_args(typ)
195195
try:
196196
return cast(type, args[index])
197-
except IndexError:
198-
raise RuntimeError(f"Expected type {typ} to have a type argument at index {index} but it did not")
197+
except IndexError as err:
198+
raise RuntimeError(f"Expected type {typ} to have a type argument at index {index} but it did not") from err
199199

200200

201201
def deepcopy_minimal(item: _T) -> _T:
@@ -275,7 +275,9 @@ def wrapper(*args: object, **kwargs: object) -> object:
275275
try:
276276
given_params.add(positional[i])
277277
except IndexError:
278-
raise TypeError(f"{func.__name__}() takes {len(positional)} argument(s) but {len(args)} were given")
278+
raise TypeError(
279+
f"{func.__name__}() takes {len(positional)} argument(s) but {len(args)} were given"
280+
) from None
279281

280282
for key in kwargs.keys():
281283
given_params.add(key)

tests/test_client.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from orb._client import Orb, AsyncOrb
1919
from orb._models import BaseModel, FinalRequestOptions
2020
from orb._exceptions import (
21+
OrbError,
2122
APIStatusError,
2223
APITimeoutError,
2324
APIConnectionError,
@@ -260,7 +261,7 @@ def test_validate_headers(self) -> None:
260261
request = client._build_request(FinalRequestOptions(method="get", url="/foo"))
261262
assert request.headers.get("Authorization") == f"Bearer {api_key}"
262263

263-
with pytest.raises(Exception):
264+
with pytest.raises(OrbError):
264265
client2 = Orb(base_url=base_url, api_key=None, _strict_response_validation=True)
265266
_ = client2
266267

@@ -922,7 +923,7 @@ def test_validate_headers(self) -> None:
922923
request = client._build_request(FinalRequestOptions(method="get", url="/foo"))
923924
assert request.headers.get("Authorization") == f"Bearer {api_key}"
924925

925-
with pytest.raises(Exception):
926+
with pytest.raises(OrbError):
926927
client2 = AsyncOrb(base_url=base_url, api_key=None, _strict_response_validation=True)
927928
_ = client2
928929

tests/test_utils/test_proxy.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ def test_recursive_proxy() -> None:
1919
assert repr(proxy) == "RecursiveLazyProxy"
2020
assert str(proxy) == "RecursiveLazyProxy"
2121
assert dir(proxy) == []
22-
assert getattr(type(proxy), "__name__") == "RecursiveLazyProxy"
22+
assert type(proxy).__name__ == "RecursiveLazyProxy"
2323
assert type(operator.attrgetter("name.foo.bar.baz")(proxy)).__name__ == "RecursiveLazyProxy"

tests/utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def assert_matches_type(
9191
traceback.print_exc()
9292
continue
9393

94-
assert False, "Did not match any variants"
94+
raise AssertionError("Did not match any variants")
9595
elif issubclass(origin, BaseModel):
9696
assert isinstance(value, type_)
9797
assert assert_matches_model(type_, cast(Any, value), path=path)

0 commit comments

Comments
 (0)