Skip to content

chore(internal): enable more lint rules #93

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/orbcorp/orb-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
2 changes: 1 addition & 1 deletion requirements-dev.lock
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pytest-asyncio==0.21.1
python-dateutil==2.8.2
pytz==2023.3.post1
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
Expand Down
2 changes: 1 addition & 1 deletion src/orb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
for __name in __all__:
if not __name.startswith("__"):
try:
setattr(__locals[__name], "__module__", "orb")
__locals[__name].__module__ = "orb"
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/orb/_streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def __stream__(self) -> Iterator[ResponseT]:
yield process_data(data=sse.json(), cast_to=cast_to, response=response)

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


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

# 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/orb/_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/orb/_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
5 changes: 3 additions & 2 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from orb._client import Orb, AsyncOrb
from orb._models import BaseModel, FinalRequestOptions
from orb._exceptions import (
OrbError,
APIStatusError,
APITimeoutError,
APIConnectionError,
Expand Down Expand Up @@ -260,7 +261,7 @@ def test_validate_headers(self) -> None:
request = client._build_request(FinalRequestOptions(method="get", url="/foo"))
assert request.headers.get("Authorization") == f"Bearer {api_key}"

with pytest.raises(Exception):
with pytest.raises(OrbError):
client2 = Orb(base_url=base_url, api_key=None, _strict_response_validation=True)
_ = client2

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

with pytest.raises(Exception):
with pytest.raises(OrbError):
client2 = AsyncOrb(base_url=base_url, api_key=None, _strict_response_validation=True)
_ = client2

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