Skip to content

Commit

Permalink
chore(internal): enable more lint rules (#273)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-bot authored Dec 7, 2023
1 parent 0d82ce4 commit 0ac62bc
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 20 deletions.
31 changes: 20 additions & 11 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,18 @@ Repository = "https://github.com/anthropics/anthropic-sdk-python"

[tool.rye]
managed = true
# version pins are in requirements-dev.lock
dev-dependencies = [
"pyright==1.1.332",
"mypy==1.7.1",
"black==23.3.0",
"respx==0.20.2",
"pytest==7.1.1",
"pytest-asyncio==0.21.1",
"ruff==0.0.282",
"isort==5.10.1",
"time-machine==2.9.0",
"nox==2023.4.22",
"pyright",
"mypy",
"black",
"respx",
"pytest",
"pytest-asyncio",
"ruff",
"isort",
"time-machine",
"nox",
"dirty-equals>=0.6.0",

]
Expand Down Expand Up @@ -132,9 +133,11 @@ extra_standard_library = ["typing_extensions"]

[tool.ruff]
line-length = 120
format = "grouped"
output-format = "grouped"
target-version = "py37"
select = [
# bugbear rules
"B",
# remove unused imports
"F401",
# bare except statements
Expand All @@ -145,6 +148,12 @@ select = [
"T201",
"T203",
]
ignore = [
# lru_cache in methods, will be fixed separately
"B019",
# mutable defaults
"B006",
]
unfixable = [
# disable auto fix for print statements
"T201",
Expand Down
9 changes: 8 additions & 1 deletion requirements-dev.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,19 @@ argcomplete==3.1.2
attrs==23.1.0
black==23.3.0
certifi==2023.7.22
charset-normalizer==3.3.2
click==8.1.7
colorlog==6.7.0
dirty-equals==0.6.0
distlib==0.3.7
distro==1.8.0
exceptiongroup==1.1.3
filelock==3.12.4
fsspec==2023.12.1
h11==0.14.0
httpcore==1.0.2
httpx==0.25.2
huggingface-hub==0.16.4
idna==3.4
iniconfig==2.0.0
isort==5.10.1
Expand All @@ -42,14 +45,18 @@ pytest==7.1.1
pytest-asyncio==0.21.1
python-dateutil==2.8.2
pytz==2023.3.post1
pyyaml==6.0.1
requests==2.31.0
respx==0.20.2
ruff==0.0.282
ruff==0.1.7
six==1.16.0
sniffio==1.3.0
time-machine==2.9.0
tokenizers==0.14.0
tomli==2.0.1
tqdm==4.66.1
typing-extensions==4.8.0
urllib3==2.1.0
virtualenv==20.24.5
# The following packages are considered to be unsafe in a requirements file:
setuptools==68.2.2
2 changes: 1 addition & 1 deletion src/anthropic/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
for __name in __all__:
if not __name.startswith("__"):
try:
setattr(__locals[__name], "__module__", "anthropic")
__locals[__name].__module__ = "anthropic"
except (TypeError, AttributeError):
# Some of our exported symbols are builtins which we can't set attributes for.
pass
4 changes: 2 additions & 2 deletions src/anthropic/_streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def __stream__(self) -> Iterator[ResponseT]:
)

# Ensure the entire stream is consumed
for sse in iterator:
for _sse in iterator:
...


Expand Down Expand Up @@ -132,7 +132,7 @@ async def __stream__(self) -> AsyncIterator[ResponseT]:
)

# Ensure the entire stream is consumed
async for sse in iterator:
async for _sse in iterator:
...


Expand Down
1 change: 1 addition & 0 deletions src/anthropic/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@


class BinaryResponseContent(ABC):
@abstractmethod
def __init__(
self,
response: Any,
Expand Down
8 changes: 5 additions & 3 deletions src/anthropic/_utils/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ def extract_type_arg(typ: type, index: int) -> type:
args = get_args(typ)
try:
return cast(type, args[index])
except IndexError:
raise RuntimeError(f"Expected type {typ} to have a type argument at index {index} but it did not")
except IndexError as err:
raise RuntimeError(f"Expected type {typ} to have a type argument at index {index} but it did not") from err


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

for key in kwargs.keys():
given_params.add(key)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_utils/test_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ def test_recursive_proxy() -> None:
assert repr(proxy) == "RecursiveLazyProxy"
assert str(proxy) == "RecursiveLazyProxy"
assert dir(proxy) == []
assert getattr(type(proxy), "__name__") == "RecursiveLazyProxy"
assert type(proxy).__name__ == "RecursiveLazyProxy"
assert type(operator.attrgetter("name.foo.bar.baz")(proxy)).__name__ == "RecursiveLazyProxy"
2 changes: 1 addition & 1 deletion tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def assert_matches_type(
traceback.print_exc()
continue

assert False, "Did not match any variants"
raise AssertionError("Did not match any variants")
elif issubclass(origin, BaseModel):
assert isinstance(value, type_)
assert assert_matches_model(type_, cast(Any, value), path=path)
Expand Down

0 comments on commit 0ac62bc

Please sign in to comment.