diff --git a/pyproject.toml b/pyproject.toml index b831f420..31c3cd8c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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", ] @@ -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 @@ -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", diff --git a/requirements-dev.lock b/requirements-dev.lock index ce154682..2ad33ff6 100644 --- a/requirements-dev.lock +++ b/requirements-dev.lock @@ -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 diff --git a/src/finch/__init__.py b/src/finch/__init__.py index c720161f..37904fae 100644 --- a/src/finch/__init__.py +++ b/src/finch/__init__.py @@ -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 diff --git a/src/finch/_streaming.py b/src/finch/_streaming.py index 913159fd..e816ca74 100644 --- a/src/finch/_streaming.py +++ b/src/finch/_streaming.py @@ -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: ... @@ -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: ... diff --git a/src/finch/_types.py b/src/finch/_types.py index e12f064d..c4f652b4 100644 --- a/src/finch/_types.py +++ b/src/finch/_types.py @@ -44,6 +44,7 @@ class BinaryResponseContent(ABC): + @abstractmethod def __init__( self, response: Any, diff --git a/src/finch/_utils/_utils.py b/src/finch/_utils/_utils.py index 83f88cc3..c874d368 100644 --- a/src/finch/_utils/_utils.py +++ b/src/finch/_utils/_utils.py @@ -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: @@ -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) diff --git a/src/finch/resources/webhooks.py b/src/finch/resources/webhooks.py index 13b88d61..40c7678b 100644 --- a/src/finch/resources/webhooks.py +++ b/src/finch/resources/webhooks.py @@ -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") @@ -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): @@ -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") @@ -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): diff --git a/tests/test_utils/test_proxy.py b/tests/test_utils/test_proxy.py index 4a7336a8..f5a7028d 100644 --- a/tests/test_utils/test_proxy.py +++ b/tests/test_utils/test_proxy.py @@ -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" diff --git a/tests/utils.py b/tests/utils.py index bc62203d..3cd9cf08 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -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)