Skip to content

Commit b070f02

Browse files
committed
Fix runff checks
1 parent da056ef commit b070f02

16 files changed

Lines changed: 50 additions & 31 deletions

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ lint:
5353
check:
5454
$(VENV_PYTHON) -m ruff format --check .
5555
$(VENV_PYTHON) -m ruff check .
56-
$(VENV_PYTHON) -m mypy $(SRC_DIR)
56+
$(VENV_PYTHON) -m pi $(SRC_DIR)
5757

5858
type-check:
5959
$(VENV_PYTHON) -m mypy $(SRC_DIR)

examples/ws_list.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
def main():
55
client = TFEClient(TFEConfig.from_env())
6-
org = "prab-sandbox01"
6+
org = "tfe-xxxxx"
77
for ws in client.workspaces.list(org):
88
print("WS:", ws.name, ws.id)
99

src/tfe/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
from .config import TFEConfig
2-
from .client import TFEClient
3-
41
from . import errors
2+
from .client import TFEClient
3+
from .config import TFEConfig
54

65
__all__ = ["TFEConfig", "TFEClient", "errors"]

src/tfe/_http.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
11
from __future__ import annotations
2-
import httpx, time, anyio
3-
from typing import Any, Mapping
4-
from .errors import *
2+
3+
import time
4+
from collections.abc import Mapping
5+
from typing import Any
6+
7+
import anyio
8+
import httpx
9+
510
from ._jsonapi import build_headers, parse_error_payload
11+
from .errors import (
12+
AuthError,
13+
NotFound,
14+
RateLimited,
15+
ServerError,
16+
TFEError,
17+
)
618

719
_RETRY_STATUSES = {429, 502, 503, 504}
820

@@ -71,7 +83,7 @@ def request(
7183
)
7284
except httpx.HTTPError as e:
7385
if attempt >= self.max_retries:
74-
raise ServerError(str(e))
86+
raise ServerError(str(e)) from e
7587
self._sleep(attempt, None)
7688
attempt += 1
7789
continue
@@ -109,7 +121,7 @@ async def arequest(
109121
)
110122
except httpx.HTTPError as e:
111123
if attempt >= self.max_retries:
112-
raise ServerError(str(e))
124+
raise ServerError(str(e)) from e
113125
await self._asleep(attempt, None)
114126
attempt += 1
115127
continue

src/tfe/_jsonapi.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from __future__ import annotations
2+
23
from typing import Any
34

45

src/tfe/aclient.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
"""
44

55
from __future__ import annotations
6-
from .config import TFEConfig
6+
77
from ._http import HTTPTransport
8-
from .resources.admin.settings import AdminSettingsAsync
8+
from .config import TFEConfig
99

1010

1111
class AsyncTFEClient:

src/tfe/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
from __future__ import annotations
2-
from .config import TFEConfig
2+
33
from ._http import HTTPTransport
4+
from .config import TFEConfig
45
from .resources.organizations import Organizations
56
from .resources.projects import Projects
67
from .resources.workspaces import Workspaces
7-
from .resources.admin.settings import AdminSettings
88

99

1010
class TFEClient:

src/tfe/config.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
from __future__ import annotations
2-
from pydantic import BaseModel, Field
2+
33
import os
44

5+
from pydantic import BaseModel, Field
6+
57

68
class TFEConfig(BaseModel):
79
address: str = Field(
@@ -24,5 +26,5 @@ class TFEConfig(BaseModel):
2426
ca_bundle: str | None = os.getenv("SSL_CERT_FILE", None)
2527

2628
@classmethod
27-
def from_env(cls) -> "TFEConfig":
29+
def from_env(cls) -> TFEConfig:
2830
return cls()

src/tfe/errors.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
from typing import Optional, List, Dict
1+
from __future__ import annotations
22

33

44
class TFEError(Exception):
55
def __init__(
66
self,
77
message: str,
88
*,
9-
status: Optional[int] = None,
10-
errors: Optional[List[Dict]] = None,
9+
status: int | None = None,
10+
errors: list[dict] | None = None,
1111
):
1212
super().__init__(message)
1313
self.status = status
@@ -21,7 +21,7 @@ class NotFound(TFEError): ...
2121

2222

2323
class RateLimited(TFEError):
24-
def __init__(self, message: str, *, retry_after: Optional[float] = None, **kw):
24+
def __init__(self, message: str, *, retry_after: float | None = None, **kw):
2525
super().__init__(message, **kw)
2626
self.retry_after = retry_after
2727

src/tfe/resources/_base.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from __future__ import annotations
2-
from typing import Iterator, AsyncIterator
2+
33
from .._http import HTTPTransport
44

55

@@ -15,8 +15,7 @@ def _list(self, path: str, *, params: dict | None = None):
1515
p.setdefault("page[size]", 100)
1616
r = self.t.request("GET", path, params=p)
1717
data = r.json().get("data", [])
18-
for item in data:
19-
yield item
18+
yield from data
2019
if len(data) < p["page[size]"]:
2120
break
2221
page += 1

0 commit comments

Comments
 (0)