Skip to content

Commit

Permalink
chore: Use modern-style type annotations (#1417)
Browse files Browse the repository at this point in the history
* chore: Use modern-style type annotations

* Remove unused imports
  • Loading branch information
edgarrmondragon authored Feb 15, 2023
1 parent 5898339 commit 707e770
Show file tree
Hide file tree
Showing 95 changed files with 316 additions and 155 deletions.
2 changes: 2 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ per-file-ignores =
singer_sdk/_singerlib/__init__.py:F401
# Templates support a generic resource of type Any.
singer_sdk/testing/templates.py:ANN401
# Disabled some checks in samples code
samples/*:ANN,D,DAR
max-complexity = 10
docstring-convention = google
allow-star-arg-any = true
6 changes: 5 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ repos:
- darglint==1.8.1
- flake8-annotations==2.9.0
- flake8-docstrings==1.6.0
files: 'singer_sdk/.*'
files: |
(?x)^(
singer_sdk/.*|
samples/.*
)$
- repo: https://github.com/asottile/pyupgrade
rev: v3.3.1
Expand Down
3 changes: 3 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# isort: dont-add-imports

# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
Expand All @@ -10,6 +12,7 @@
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#

import os
import sys

Expand Down
1 change: 1 addition & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def mypy(session: Session) -> None:
session.install(
"mypy",
"pytest",
"importlib-resources",
"sqlalchemy2-stubs",
"types-python-dateutil",
"types-requests",
Expand Down
20 changes: 10 additions & 10 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ pytest-snapshot = "^0.9.0"
exclude = ".*simpleeval.*"

[tool.isort]
add_imports = [
"from __future__ import annotations",
]
profile = "black"
multi_line_output = 3 # Vertical Hanging Indent
src_paths = "singer_sdk"
Expand Down
2 changes: 2 additions & 0 deletions samples/aapl/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
$ poetry run python samples/aapl
"""

from __future__ import annotations

from aapl import Fundamentals

Fundamentals.cli()
2 changes: 2 additions & 0 deletions samples/aapl/aapl.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""A simple tap with one big record and schema."""

from __future__ import annotations

import json
from pathlib import Path

Expand Down
2 changes: 2 additions & 0 deletions samples/sample_mapper/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
"""Stream maps transformer."""

from __future__ import annotations
8 changes: 5 additions & 3 deletions samples/sample_mapper/mapper.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
"""A sample inline mapper app."""

from __future__ import annotations

from pathlib import PurePath
from typing import Generator, List, Optional, Union
from typing import Generator

import singer_sdk._singerlib as singer
import singer_sdk.typing as th
Expand Down Expand Up @@ -42,7 +44,7 @@ class StreamTransform(InlineMapper):

def __init__(
self,
config: Optional[Union[dict, PurePath, str, List[Union[PurePath, str]]]] = None,
config: dict | PurePath | str | list[PurePath | str] | None = None,
parse_env_config: bool = False,
validate_config: bool = True,
) -> None:
Expand Down Expand Up @@ -120,7 +122,7 @@ def map_record_message(
self.logger.info(stream_map.stream_alias)
yield record_message

def map_state_message(self, message_dict: dict) -> List[singer.Message]:
def map_state_message(self, message_dict: dict) -> list[singer.Message]:
"""Do nothing to the message.
Args:
Expand Down
6 changes: 3 additions & 3 deletions samples/sample_tap_bigquery/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""A sample implementation for BigQuery."""

from typing import List, Tuple, Type
from __future__ import annotations

from singer_sdk import SQLConnector, SQLStream, SQLTap
from singer_sdk import typing as th # JSON schema typing helpers
Expand All @@ -15,7 +15,7 @@ def get_sqlalchemy_url(cls, config: dict) -> str:

def get_object_names(
self, engine, inspected, schema_name: str
) -> List[Tuple[str, bool]]:
) -> list[tuple[str, bool]]:
"""Return discoverable object names."""
# Bigquery inspections returns table names in the form
# `schema_name.table_name` which later results in the project name
Expand Down Expand Up @@ -48,7 +48,7 @@ class TapBigQuery(SQLTap):
),
).to_dict()

default_stream_class: Type[SQLStream] = BigQueryStream
default_stream_class: type[SQLStream] = BigQueryStream


__all__ = ["TapBigQuery", "BigQueryConnector", "BigQueryStream"]
2 changes: 2 additions & 0 deletions samples/sample_tap_countries/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
"""Countries API Sample."""

from __future__ import annotations
2 changes: 2 additions & 0 deletions samples/sample_tap_countries/__main__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from samples.sample_tap_countries.countries_tap import SampleTapCountries

SampleTapCountries.cli()
2 changes: 2 additions & 0 deletions samples/sample_tap_countries/countries_streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
- https://countries.trevorblades.com/
"""

from __future__ import annotations

import abc
from pathlib import Path

Expand Down
4 changes: 2 additions & 2 deletions samples/sample_tap_countries/countries_tap.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
- https://countries.trevorblades.com/
"""

from typing import List
from __future__ import annotations

from samples.sample_tap_countries.countries_streams import (
ContinentsStream,
Expand All @@ -22,7 +22,7 @@ class SampleTapCountries(Tap):
name: str = "sample-tap-countries"
config_jsonschema = PropertiesList().to_dict()

def discover_streams(self) -> List[Stream]:
def discover_streams(self) -> list[Stream]:
"""Return a list of discovered streams."""
return [
CountriesStream(tap=self),
Expand Down
2 changes: 2 additions & 0 deletions samples/sample_tap_gitlab/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
"""Gitlab API Sample."""

from __future__ import annotations
2 changes: 2 additions & 0 deletions samples/sample_tap_gitlab/gitlab_graphql_streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
# - https://gitlab.com/-/graphql-explorer
"""

from __future__ import annotations

from pathlib import Path

from singer_sdk.streams import GraphQLStream
Expand Down
4 changes: 2 additions & 2 deletions samples/sample_tap_gitlab/gitlab_tap.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Sample tap test for tap-gitlab."""

from typing import List
from __future__ import annotations

from samples.sample_tap_gitlab.gitlab_rest_streams import (
CommitsStream,
Expand Down Expand Up @@ -40,6 +40,6 @@ class SampleTapGitlab(Tap):
Property("start_date", DateTimeType, required=True),
).to_dict()

def discover_streams(self) -> List[Stream]:
def discover_streams(self) -> list[Stream]:
"""Return a list of discovered streams."""
return [stream_class(tap=self) for stream_class in STREAM_TYPES]
2 changes: 2 additions & 0 deletions samples/sample_tap_google_analytics/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
"""Google Analytics sample."""

from __future__ import annotations
5 changes: 3 additions & 2 deletions samples/sample_tap_google_analytics/ga_tap.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
"""Sample tap test for tap-google-analytics."""

from __future__ import annotations

import json
from pathlib import Path
from typing import List

from samples.sample_tap_google_analytics.ga_tap_stream import (
GASimpleSampleStream,
Expand All @@ -29,6 +30,6 @@ class SampleTapGoogleAnalytics(Tap):
Property("private_key", StringType(), required=True, secret=True),
).to_dict()

def discover_streams(self) -> List[SampleGoogleAnalyticsStream]:
def discover_streams(self) -> list[SampleGoogleAnalyticsStream]:
"""Return a list of all streams."""
return [GASimpleSampleStream(tap=self)]
12 changes: 7 additions & 5 deletions samples/sample_tap_google_analytics/ga_tap_stream.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
"""Sample tap stream test for tap-google-analytics."""

from __future__ import annotations

from pathlib import Path
from typing import Any, Iterable, List, Optional, cast
from typing import Any, Iterable, cast

import pendulum

Expand Down Expand Up @@ -30,8 +32,8 @@ class SampleGoogleAnalyticsStream(RESTStream):
rest_method = "POST"

# Child class overrides:
dimensions: List[str] = []
metrics: List[str] = []
dimensions: list[str] = []
metrics: list[str] = []

@property
def authenticator(self) -> GoogleJWTAuthenticator:
Expand All @@ -43,8 +45,8 @@ def authenticator(self) -> GoogleJWTAuthenticator:
)

def prepare_request_payload(
self, context: Optional[dict], next_page_token: Optional[Any]
) -> Optional[dict]:
self, context: dict | None, next_page_token: Any | None
) -> dict | None:
"""Prepare the data payload for the REST API request."""
# params = self.get_url_params(context, next_page_token)
request_def = {
Expand Down
6 changes: 6 additions & 0 deletions samples/sample_tap_hostile/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
"""A sample tap for testing SQL target property name transformations."""

from __future__ import annotations

from .hostile_tap import SampleTapHostile

__all__ = [
"SampleTapHostile",
]
4 changes: 2 additions & 2 deletions samples/sample_tap_hostile/hostile_tap.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""A sample tap for testing SQL target property name transformations."""

from typing import List
from __future__ import annotations

from samples.sample_tap_hostile.hostile_streams import HostilePropertyNamesStream
from singer_sdk import Stream, Tap
Expand All @@ -13,7 +13,7 @@ class SampleTapHostile(Tap):
name: str = "sample-tap-hostile"
config_jsonschema = PropertiesList().to_dict()

def discover_streams(self) -> List[Stream]:
def discover_streams(self) -> list[Stream]:
"""Return a list of discovered streams."""
return [
HostilePropertyNamesStream(tap=self),
Expand Down
6 changes: 4 additions & 2 deletions samples/sample_tap_sqlite/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""A sample implementation for SQLite."""

from typing import Any, Dict
from __future__ import annotations

from typing import Any

import sqlalchemy

Expand All @@ -16,7 +18,7 @@ class SQLiteConnector(SQLConnector):
This class handles all DDL and type conversions.
"""

def get_sqlalchemy_url(self, config: Dict[str, Any]) -> str:
def get_sqlalchemy_url(self, config: dict[str, Any]) -> str:
"""Generates a SQLAlchemy URL for SQLite."""
return f"sqlite:///{config[DB_PATH_CONFIG]}"

Expand Down
2 changes: 2 additions & 0 deletions samples/sample_target_csv/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
"""Module test for target-csv functionality."""

from __future__ import annotations
2 changes: 2 additions & 0 deletions samples/sample_target_csv/__main__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from samples.sample_target_csv.csv_target import SampleTargetCSV

SampleTargetCSV.cli()
2 changes: 2 additions & 0 deletions samples/sample_target_csv/csv_target.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Sample target test for target-csv."""

from __future__ import annotations

from samples.sample_target_csv.csv_target_sink import SampleCSVTargetSink
from singer_sdk import typing as th
from singer_sdk.target_base import Target
Expand Down
2 changes: 2 additions & 0 deletions samples/sample_target_csv/csv_target_sink.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Sample Parquet target stream class, which handles writing streams."""

from __future__ import annotations

import csv
from pathlib import Path

Expand Down
2 changes: 2 additions & 0 deletions samples/sample_target_parquet/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""Module test for target-parquet functionality."""


from __future__ import annotations

# Reuse the tap connection rather than create a new target connection:
from samples.sample_target_parquet.parquet_target import SampleTargetParquet
from samples.sample_target_parquet.parquet_target_sink import SampleParquetTargetSink
Expand Down
2 changes: 2 additions & 0 deletions samples/sample_target_parquet/parquet_target.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Sample target test for target-parquet."""

from __future__ import annotations

from samples.sample_target_parquet.parquet_target_sink import SampleParquetTargetSink
from singer_sdk import typing as th
from singer_sdk.target_base import Target
Expand Down
Loading

0 comments on commit 707e770

Please sign in to comment.