Skip to content

Commit 0ac62bc

Browse files
chore(internal): enable more lint rules (#273)
1 parent 0d82ce4 commit 0ac62bc

File tree

8 files changed

+39
-20
lines changed

8 files changed

+39
-20
lines changed

pyproject.toml

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,18 @@ Repository = "https://github.com/anthropics/anthropic-sdk-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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,19 @@ argcomplete==3.1.2
1313
attrs==23.1.0
1414
black==23.3.0
1515
certifi==2023.7.22
16+
charset-normalizer==3.3.2
1617
click==8.1.7
1718
colorlog==6.7.0
1819
dirty-equals==0.6.0
1920
distlib==0.3.7
2021
distro==1.8.0
2122
exceptiongroup==1.1.3
2223
filelock==3.12.4
24+
fsspec==2023.12.1
2325
h11==0.14.0
2426
httpcore==1.0.2
2527
httpx==0.25.2
28+
huggingface-hub==0.16.4
2629
idna==3.4
2730
iniconfig==2.0.0
2831
isort==5.10.1
@@ -42,14 +45,18 @@ pytest==7.1.1
4245
pytest-asyncio==0.21.1
4346
python-dateutil==2.8.2
4447
pytz==2023.3.post1
48+
pyyaml==6.0.1
49+
requests==2.31.0
4550
respx==0.20.2
46-
ruff==0.0.282
51+
ruff==0.1.7
4752
six==1.16.0
4853
sniffio==1.3.0
4954
time-machine==2.9.0
5055
tokenizers==0.14.0
5156
tomli==2.0.1
57+
tqdm==4.66.1
5258
typing-extensions==4.8.0
59+
urllib3==2.1.0
5360
virtualenv==20.24.5
5461
# The following packages are considered to be unsafe in a requirements file:
5562
setuptools==68.2.2

src/anthropic/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
for __name in __all__:
8080
if not __name.startswith("__"):
8181
try:
82-
setattr(__locals[__name], "__module__", "anthropic")
82+
__locals[__name].__module__ = "anthropic"
8383
except (TypeError, AttributeError):
8484
# Some of our exported symbols are builtins which we can't set attributes for.
8585
pass

src/anthropic/_streaming.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def __stream__(self) -> Iterator[ResponseT]:
7070
)
7171

7272
# Ensure the entire stream is consumed
73-
for sse in iterator:
73+
for _sse in iterator:
7474
...
7575

7676

@@ -132,7 +132,7 @@ async def __stream__(self) -> AsyncIterator[ResponseT]:
132132
)
133133

134134
# Ensure the entire stream is consumed
135-
async for sse in iterator:
135+
async for _sse in iterator:
136136
...
137137

138138

src/anthropic/_types.py

Lines changed: 1 addition & 0 deletions
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/anthropic/_utils/_utils.py

Lines changed: 5 additions & 3 deletions
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_utils/test_proxy.py

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

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