Skip to content

Commit

Permalink
chore: Enable TCH Ruff checks (#1514)
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarrmondragon authored Mar 20, 2023
1 parent 0d0eaec commit fbbb293
Show file tree
Hide file tree
Showing 38 changed files with 203 additions and 101 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ select = [
"RSE", # flake8-raise
"RET", # flake8-return
"SIM", # flake8-simplify
"TCH", # flake8-type-checking
]
src = ["samples", "singer_sdk", "tests"]
target-version = "py37"
Expand Down
6 changes: 4 additions & 2 deletions samples/sample_mapper/mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@

from __future__ import annotations

from pathlib import PurePath
from typing import Generator
from typing import TYPE_CHECKING, Generator

import singer_sdk._singerlib as singer
import singer_sdk.typing as th
from singer_sdk.helpers._util import utc_now
from singer_sdk.mapper import PluginMapper
from singer_sdk.mapper_base import InlineMapper

if TYPE_CHECKING:
from pathlib import PurePath


class StreamTransform(InlineMapper):
"""A map transformer which implements the Stream Maps capability."""
Expand Down
4 changes: 3 additions & 1 deletion singer_sdk/_singerlib/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
import sys
import typing as t
from dataclasses import asdict, dataclass, field
from datetime import datetime

import pytz
import simplejson as json

if t.TYPE_CHECKING:
from datetime import datetime


class SingerMessageType(str, enum.Enum):
"""Singer specification message types."""
Expand Down
9 changes: 6 additions & 3 deletions singer_sdk/authenticators.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
from __future__ import annotations

import base64
import logging
import math
from datetime import datetime, timedelta
from types import MappingProxyType
from typing import Any, Mapping
from typing import TYPE_CHECKING, Any, Mapping
from urllib.parse import parse_qs, urlencode, urlsplit, urlunsplit

import jwt
Expand All @@ -16,7 +15,11 @@
from cryptography.hazmat.primitives import serialization

from singer_sdk.helpers._util import utc_now
from singer_sdk.streams import Stream as RESTStreamBase

if TYPE_CHECKING:
import logging

from singer_sdk.streams import Stream as RESTStreamBase


def _add_parameters(initial_url: str, extra_parameters: dict) -> str:
Expand Down
6 changes: 4 additions & 2 deletions singer_sdk/connectors/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@
from contextlib import contextmanager
from datetime import datetime
from functools import lru_cache
from typing import Any, Iterable, Iterator, cast
from typing import TYPE_CHECKING, Any, Iterable, Iterator, cast

import sqlalchemy
from sqlalchemy.engine import Engine
from sqlalchemy.engine.reflection import Inspector

from singer_sdk import typing as th
from singer_sdk._singerlib import CatalogEntry, MetadataMapping, Schema
from singer_sdk.exceptions import ConfigValidationError

if TYPE_CHECKING:
from sqlalchemy.engine.reflection import Inspector


class SQLConnector:
"""Base class for SQLAlchemy-based connectors.
Expand Down
5 changes: 4 additions & 1 deletion singer_sdk/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

from __future__ import annotations

import requests
import typing as t

if t.TYPE_CHECKING:
import requests


class ConfigValidationError(Exception):
Expand Down
9 changes: 6 additions & 3 deletions singer_sdk/helpers/_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@
from __future__ import annotations

from copy import deepcopy
from logging import Logger
from typing import Any
from typing import TYPE_CHECKING, Any

from memoization import cached

from singer_sdk._singerlib import Catalog, SelectionMask
from singer_sdk.helpers._typing import is_object_type

if TYPE_CHECKING:
from logging import Logger

from singer_sdk._singerlib import Catalog, SelectionMask

_MAX_LRU_CACHE = 500


Expand Down
6 changes: 4 additions & 2 deletions singer_sdk/helpers/_resources.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from __future__ import annotations

import sys
from types import ModuleType
from typing import cast
from typing import TYPE_CHECKING, cast

if TYPE_CHECKING:
from types import ModuleType

if sys.version_info < (3, 9):
import importlib_resources
Expand Down
6 changes: 4 additions & 2 deletions singer_sdk/helpers/_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

from __future__ import annotations

import datetime
from typing import Any, Callable, cast
from typing import TYPE_CHECKING, Any, Callable, cast

from singer_sdk.exceptions import InvalidStreamSortException
from singer_sdk.helpers._typing import to_json_compatible

if TYPE_CHECKING:
import datetime

PROGRESS_MARKERS = "progress_markers"
PROGRESS_MARKER_NOTE = "Note"
SIGNPOST_MARKER = "replication_key_signpost"
Expand Down
6 changes: 4 additions & 2 deletions singer_sdk/helpers/_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@

import copy
import datetime
import logging
from enum import Enum
from functools import lru_cache
from typing import Any, cast
from typing import TYPE_CHECKING, Any, cast

import pendulum

if TYPE_CHECKING:
import logging

_MAX_TIMESTAMP = "9999-12-31 23:59:59.999999"
_MAX_TIME = "23:59:59.999999"
JSONSCHEMA_ANNOTATION_SECRET = "secret"
Expand Down
6 changes: 4 additions & 2 deletions singer_sdk/helpers/jsonpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

from __future__ import annotations

from typing import Any, Generator
from typing import TYPE_CHECKING, Any, Generator

import jsonpath_ng
import memoization
from jsonpath_ng.ext import parse

if TYPE_CHECKING:
import jsonpath_ng


def extract_jsonpath(expression: str, input: dict | list) -> Generator[Any, None, None]:
"""Extract records from an input based on a JSONPath expression.
Expand Down
17 changes: 10 additions & 7 deletions singer_sdk/mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@
import datetime
import hashlib
import logging
import sys
from typing import Any, Callable, Dict, Union
from typing import TYPE_CHECKING, Any, Callable, Dict, Union

from singer_sdk._singerlib.catalog import Catalog
from singer_sdk.exceptions import MapExpressionError, StreamMapConfigError
from singer_sdk.helpers import _simpleeval as simpleeval
from singer_sdk.helpers._catalog import get_selected_schema
Expand All @@ -33,10 +31,15 @@
StringType,
)

if sys.version_info >= (3, 10):
from typing import TypeAlias
else:
from typing_extensions import TypeAlias
if TYPE_CHECKING:
import sys

if sys.version_info >= (3, 10):
from typing import TypeAlias
else:
from typing_extensions import TypeAlias

from singer_sdk._singerlib.catalog import Catalog


MAPPER_ELSE_OPTION = "__else__"
Expand Down
6 changes: 4 additions & 2 deletions singer_sdk/mapper_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
from __future__ import annotations

import abc
from io import FileIO
from typing import Callable, Iterable
from typing import TYPE_CHECKING, Callable, Iterable

import click

Expand All @@ -16,6 +15,9 @@
from singer_sdk.io_base import SingerReader
from singer_sdk.plugin_base import PluginBase

if TYPE_CHECKING:
from io import FileIO


class InlineMapper(PluginBase, SingerReader, metaclass=abc.ABCMeta):
"""Abstract base class for inline mappers."""
Expand Down
6 changes: 4 additions & 2 deletions singer_sdk/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
from dataclasses import asdict, dataclass, field
from pathlib import Path
from time import time
from types import TracebackType
from typing import Any, Generic, Mapping, TypeVar
from typing import TYPE_CHECKING, Any, Generic, Mapping, TypeVar

import yaml

from singer_sdk.helpers._resources import Traversable, get_package_files

if TYPE_CHECKING:
from types import TracebackType

DEFAULT_LOG_INTERVAL = 60.0
METRICS_LOGGER_NAME = __name__
METRICS_LOG_LEVEL_SETTING = "metrics_log_level"
Expand Down
7 changes: 4 additions & 3 deletions singer_sdk/pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@

import sys
from abc import ABCMeta, abstractmethod
from typing import Any, Generic, Iterable, Optional, TypeVar
from typing import TYPE_CHECKING, Any, Generic, Iterable, Optional, TypeVar
from urllib.parse import ParseResult, urlparse

from requests import Response

from singer_sdk.helpers.jsonpath import extract_jsonpath

if sys.version_info >= (3, 8):
from typing import Protocol
else:
from typing_extensions import Protocol

if TYPE_CHECKING:
from requests import Response

T = TypeVar("T")
TPageToken = TypeVar("TPageToken")

Expand Down
6 changes: 4 additions & 2 deletions singer_sdk/plugin_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from collections import OrderedDict
from pathlib import PurePath
from types import MappingProxyType
from typing import Any, Callable, Mapping, cast
from typing import TYPE_CHECKING, Any, Callable, Mapping, cast

import click
from jsonschema import Draft7Validator
Expand All @@ -27,9 +27,11 @@
CapabilitiesEnum,
PluginCapabilities,
)
from singer_sdk.mapper import PluginMapper
from singer_sdk.typing import extend_validator_with_defaults

if TYPE_CHECKING:
from singer_sdk.mapper import PluginMapper

SDK_PACKAGE_NAME = "singer_sdk"


Expand Down
9 changes: 6 additions & 3 deletions singer_sdk/sinks/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
import time
from gzip import GzipFile
from gzip import open as gzip_open
from logging import Logger
from types import MappingProxyType
from typing import IO, Any, Mapping, Sequence
from typing import IO, TYPE_CHECKING, Any, Mapping, Sequence

from dateutil import parser
from jsonschema import Draft7Validator, FormatChecker
Expand All @@ -27,7 +26,11 @@
get_datelike_property_type,
handle_invalid_timestamp_in_record,
)
from singer_sdk.plugin_base import PluginBase

if TYPE_CHECKING:
from logging import Logger

from singer_sdk.plugin_base import PluginBase

JSONSchemaValidator = Draft7Validator

Expand Down
9 changes: 6 additions & 3 deletions singer_sdk/sinks/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,22 @@
from collections import defaultdict
from copy import copy
from textwrap import dedent
from typing import Any, Iterable
from typing import TYPE_CHECKING, Any, Iterable

import sqlalchemy
from pendulum import now
from sqlalchemy.sql import Executable
from sqlalchemy.sql.expression import bindparam

from singer_sdk.connectors import SQLConnector
from singer_sdk.exceptions import ConformedNameClashException
from singer_sdk.helpers._conformers import replace_leading_digit
from singer_sdk.plugin_base import PluginBase
from singer_sdk.sinks.batch import BatchSink

if TYPE_CHECKING:
from sqlalchemy.sql import Executable

from singer_sdk.plugin_base import PluginBase


class SQLSink(BatchSink):
"""SQL-type sink type."""
Expand Down
18 changes: 15 additions & 3 deletions singer_sdk/streams/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,19 @@
import gzip
import itertools
import json
import logging
from os import PathLike
from pathlib import Path
from types import MappingProxyType
from typing import Any, Generator, Iterable, Iterator, Mapping, TypeVar, cast
from typing import (
TYPE_CHECKING,
Any,
Generator,
Iterable,
Iterator,
Mapping,
TypeVar,
cast,
)
from uuid import uuid4

import pendulum
Expand Down Expand Up @@ -46,7 +54,11 @@
)
from singer_sdk.helpers._util import utc_now
from singer_sdk.mapper import RemoveRecordTransform, SameRecordTransform, StreamMap
from singer_sdk.plugin_base import PluginBase as TapBaseClass

if TYPE_CHECKING:
import logging

from singer_sdk.plugin_base import PluginBase as TapBaseClass

# Replication methods
REPLICATION_FULL_TABLE = "FULL_TABLE"
Expand Down
Loading

0 comments on commit fbbb293

Please sign in to comment.