Skip to content

Commit

Permalink
chore(internal): enable more lint rules (#217)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-bot authored Dec 7, 2023
1 parent 14c8df0 commit 61018d4
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 28 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/Finch-API/finch-api-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/finch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
for __name in __all__:
if not __name.startswith("__"):
try:
setattr(__locals[__name], "__module__", "finch")
__locals[__name].__module__ = "finch"
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/finch/_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/finch/_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/finch/_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
16 changes: 8 additions & 8 deletions src/finch/resources/webhooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ def verify_signature(

try:
parsedSecret = base64.b64decode(secret)
except Exception:
raise ValueError("Bad secret")
except Exception as err:
raise ValueError("Bad secret") from err

msg_id = get_required_header(headers, "finch-event-id")
msg_timestamp = get_required_header(headers, "finch-timestamp")
Expand All @@ -68,8 +68,8 @@ def verify_signature(

try:
timestamp = datetime.fromtimestamp(float(msg_timestamp), tz=timezone.utc)
except Exception:
raise ValueError("Invalid timestamp header: " + msg_timestamp + ". Could not convert to timestamp")
except Exception as err:
raise ValueError("Invalid timestamp header: " + msg_timestamp + ". Could not convert to timestamp") from err

# too old
if timestamp < (now - webhook_tolerance):
Expand Down Expand Up @@ -152,8 +152,8 @@ def verify_signature(

try:
parsedSecret = base64.b64decode(secret)
except Exception:
raise ValueError("Bad secret")
except Exception as err:
raise ValueError("Bad secret") from err

msg_id = get_required_header(headers, "finch-event-id")
msg_timestamp = get_required_header(headers, "finch-timestamp")
Expand All @@ -164,8 +164,8 @@ def verify_signature(

try:
timestamp = datetime.fromtimestamp(float(msg_timestamp), tz=timezone.utc)
except Exception:
raise ValueError("Invalid timestamp header: " + msg_timestamp + ". Could not convert to timestamp")
except Exception as err:
raise ValueError("Invalid timestamp header: " + msg_timestamp + ". Could not convert to timestamp") from err

# too old
if timestamp < (now - webhook_tolerance):
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 61018d4

Please sign in to comment.