Skip to content

Commit b4034f6

Browse files
chore: Use mypy correctly and introduce ty
1 parent 7583cbe commit b4034f6

File tree

7 files changed

+418
-201
lines changed

7 files changed

+418
-201
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ name: Test Tap
33
on:
44
pull_request:
55
paths-ignore:
6-
- '**/README.md'
6+
- "**/README.md"
77
push:
88
branches: [main]
99
paths-ignore:
10-
- '**/README.md'
10+
- "**/README.md"
1111

1212
env:
1313
FORCE_COLOR: 1
@@ -41,7 +41,7 @@ jobs:
4141
allow-prereleases: true
4242
- uses: astral-sh/setup-uv@85856786d1ce8acfbcc2f13a5f3fbd6b938f9f41 # v7.1.2
4343
with:
44-
version: ">=0.5.19"
44+
version: ">=0.9"
4545
- run: >
4646
uvx
4747
--with tox-uv

.pre-commit-config.yaml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,3 @@ repos:
4545
rev: 0.9.13
4646
hooks:
4747
- id: uv-lock
48-
49-
- repo: https://github.com/pre-commit/mirrors-mypy
50-
rev: v1.19.0
51-
hooks:
52-
- id: mypy
53-
pass_filenames: true
54-
additional_dependencies:
55-
- types-requests
56-
- types-PyYAML

pyproject.toml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ dynamic = [ "version" ]
3535
dependencies = [
3636
"backports-datetime-fromisoformat~=2.0.1; python_full_version<'3.11'",
3737
"pyyaml~=6.0",
38-
"singer-sdk>=0.52,<0.54",
38+
"singer-sdk~=0.53.4",
3939
"typing-extensions>=4.14.1",
4040
]
4141

@@ -48,8 +48,11 @@ scripts.tap-dbt = "tap_dbt.tap:cli"
4848
dev = [
4949
"deptry>=0.14.2",
5050
"faker>=17.6",
51-
"pytest>=8,<10",
51+
"mypy>=1.19",
52+
"pytest>=9",
5253
"responses~=0.25.0",
54+
"ty>=0.0.1a29",
55+
"types-pyyaml>=6.0.12.20250915",
5356
"types-requests>=2.32.4.20250809",
5457
]
5558

@@ -58,7 +61,7 @@ fallback-version = "0.0.0"
5861
source = "vcs"
5962

6063
[tool.uv]
61-
required-version = ">=0.5.19"
64+
required-version = ">=0.9"
6265

6366
[tool.ruff]
6467
line-length = 88
@@ -104,3 +107,9 @@ DEP002 = [ "backports-datetime-fromisoformat" ]
104107

105108
[tool.pyproject-fmt]
106109
max_supported_python = "3.14"
110+
111+
[tool.mypy]
112+
warn_redundant_casts = true
113+
warn_unreachable = true
114+
warn_unused_ignores = true
115+
warn_unused_configs = true

tap_dbt/client.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
from __future__ import annotations
44

55
import importlib.resources
6-
import typing as t
6+
import sys
77
from abc import abstractmethod
88
from functools import cache, cached_property
9+
from typing import Any
910

1011
import yaml
1112
from singer_sdk import RESTStream
@@ -15,9 +16,14 @@
1516

1617
from tap_dbt import schemas
1718

19+
if sys.version_info >= (3, 12):
20+
from typing import override
21+
else:
22+
from typing_extensions import override
23+
1824

1925
@cache
20-
def load_openapi(api_version: str) -> dict[str, t.Any]:
26+
def load_openapi(api_version: str) -> dict[str, Any]:
2127
"""Load the OpenAPI specification from the package.
2228
2329
Returns:
@@ -32,41 +38,44 @@ def load_openapi(api_version: str) -> dict[str, t.Any]:
3238
class DBTStream(RESTStream):
3339
"""dbt stream class."""
3440

35-
primary_keys: t.ClassVar[list[str]] = ["id"]
41+
primary_keys = ("id",)
3642
records_jsonpath = "$.data[*]"
3743
api_version = "v2"
3844

45+
@override
3946
@property
4047
def url_base(self) -> str:
4148
"""Base URL for this stream."""
4249
base_url: str = self.config["base_url"]
4350
return f"{(base_url.rsplit('/', 1))[0]}/{self.api_version}"
4451

52+
@override
4553
@property
4654
def http_headers(self) -> dict:
4755
"""HTTP headers for this stream."""
4856
headers = super().http_headers
4957
headers["Accept"] = "application/json"
5058
return headers
5159

60+
@override
5261
@property
5362
def authenticator(self) -> APIAuthenticatorBase:
5463
"""Return the authenticator for this stream."""
5564
return SimpleAuthenticator(
56-
stream=self,
5765
auth_headers={
5866
"Authorization": f"Token {self.config.get('api_key')}",
5967
},
6068
)
6169

62-
def _resolve_openapi_ref(self) -> dict[str, t.Any]:
70+
def _resolve_openapi_ref(self) -> dict[str, Any]:
6371
schema = {"$ref": f"#/components/schemas/{self.openapi_ref}"}
6472
openapi = load_openapi(self.api_version)
6573
schema["components"] = openapi["components"]
6674
return resolve_schema_references(schema)
6775

76+
@override
6877
@cached_property
69-
def schema(self) -> dict[str, t.Any]:
78+
def schema(self) -> dict[str, Any]:
7079
"""Return the schema for this stream.
7180
7281
Returns:
@@ -83,7 +92,7 @@ def append_null_nested(schema: dict) -> dict:
8392
if "properties" in schema:
8493
new_schema["properties"] = {}
8594
for p_name, p_schema in schema["properties"].items():
86-
if p_name not in self.primary_keys:
95+
if p_name not in self.primary_keys: # ty: ignore[unsupported-operator]
8796
new_schema["properties"][p_name] = append_null_nested(p_schema)
8897
else:
8998
new_schema["properties"][p_name] = p_schema

0 commit comments

Comments
 (0)