Skip to content

Commit

Permalink
chore: Enable PGH (pygrep-hooks) Ruff checks (#1555)
Browse files Browse the repository at this point in the history
* chore: Enable `PGH` (pygrep-hooks) Ruff checks

* Add type var to type checking block
  • Loading branch information
edgarrmondragon authored Mar 28, 2023
1 parent 9397437 commit 61eecbf
Show file tree
Hide file tree
Showing 13 changed files with 30 additions and 30 deletions.
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ plugins = [
]
python_version = "3.8"
warn_unused_configs = true
warn_unused_ignores = true
warn_return_any = true

[[tool.mypy.overrides]]
Expand Down Expand Up @@ -249,6 +250,7 @@ select = [
"ARG", # flake8-unused-arguments
"PTH", # flake8-use-pathlib
"ERA", # eradicate
"PGH", # pygrep-hooks
]
src = ["samples", "singer_sdk", "tests"]
target-version = "py37"
Expand Down
2 changes: 1 addition & 1 deletion singer_sdk/_singerlib/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def root(self) -> StreamMetadata:
Returns:
Stream metadata.
"""
return self[()] # type: ignore
return self[()] # type: ignore[return-value]

@classmethod
def get_standard_metadata(
Expand Down
2 changes: 1 addition & 1 deletion singer_sdk/authenticators.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def __call__(cls, *args: Any, **kwargs: Any) -> Any: # noqa: ANN401
"""
if cls.__single_instance:
return cls.__single_instance
single_obj = cls.__new__(cls, None) # type: ignore
single_obj = cls.__new__(cls, None) # type: ignore[call-overload]
single_obj.__init__(*args, **kwargs)
cls.__single_instance = single_obj
return single_obj
Expand Down
15 changes: 6 additions & 9 deletions singer_sdk/helpers/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@

from __future__ import annotations

try:
from typing import final
except ImportError:
# Final not available until Python3.8
final = lambda f: f # noqa: E731
import sys

try:
if sys.version_info < (3, 8):
import importlib_metadata as metadata
from typing_extensions import final
else:
from importlib import metadata
except ImportError:
# Running on pre-3.8 Python; use importlib-metadata package
import importlib_metadata as metadata # type: ignore
from typing import final

__all__ = ["metadata", "final"]
2 changes: 1 addition & 1 deletion singer_sdk/helpers/_simpleeval.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
# builtins is a dict in python >3.6 but a module before
DISALLOW_FUNCTIONS = {type, isinstance, eval, getattr, setattr, repr, compile, open}
if hasattr(__builtins__, "help") or (
hasattr(__builtins__, "__contains__") and "help" in __builtins__ # type: ignore
hasattr(__builtins__, "__contains__") and "help" in __builtins__
):
# PyInstaller environment doesn't include this module.
DISALLOW_FUNCTIONS.add(help)
Expand Down
13 changes: 7 additions & 6 deletions singer_sdk/helpers/_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@

from __future__ import annotations

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

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

if TYPE_CHECKING:
import datetime

_T = TypeVar("_T", datetime.datetime, str, int, float)

PROGRESS_MARKERS = "progress_markers"
PROGRESS_MARKER_NOTE = "Note"
SIGNPOST_MARKER = "replication_key_signpost"
Expand Down Expand Up @@ -224,13 +226,12 @@ def increment_state(


def _greater_than_signpost(
signpost: datetime.datetime | str | int | float,
new_value: datetime.datetime | str | int | float,
signpost: _T,
new_value: _T,
) -> bool:
"""Compare and return True if new_value is greater than signpost."""
return ( # fails if signpost and bookmark are incompatible types
new_value > signpost # type: ignore
)
# fails if signpost and bookmark are incompatible types
return new_value > signpost


def finalize_state_progress_markers(stream_or_partition_state: dict) -> dict | None:
Expand Down
2 changes: 1 addition & 1 deletion singer_sdk/mapper_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def cli(
cls._env_prefix,
)

mapper = cls( # type: ignore # Ignore 'type not callable'
mapper = cls( # type: ignore[operator]
config=config_dict,
validate_config=validate_config,
)
Expand Down
2 changes: 1 addition & 1 deletion singer_sdk/streams/graphql.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class GraphQLStream(RESTStream, metaclass=abc.ABCMeta):
rest_method = "POST"

@classproperty
def records_jsonpath(cls) -> str: # type: ignore # OK: str vs @classproperty
def records_jsonpath(cls) -> str: # type: ignore[override]
"""Get the JSONPath expression to extract records from an API response.
Returns:
Expand Down
4 changes: 2 additions & 2 deletions singer_sdk/streams/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ def get_new_paginator(self) -> BaseAPIPaginator:
DeprecationWarning,
stacklevel=2,
)
return LegacyStreamPaginator(self) # type: ignore
return LegacyStreamPaginator(self)

if self.next_page_token_jsonpath:
return JSONPathPaginator(self.next_page_token_jsonpath)
Expand Down Expand Up @@ -588,7 +588,7 @@ def backoff_wait_generator(self) -> Generator[float, None, None]:
Returns:
The wait generator
"""
return backoff.expo(factor=2) # type: ignore # ignore 'Returning Any'
return backoff.expo(factor=2)

def backoff_max_tries(self) -> int:
"""The number of attempts before giving up when retrying requests.
Expand Down
4 changes: 2 additions & 2 deletions singer_sdk/tap_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def __init__(
if isinstance(catalog, Catalog):
self._input_catalog = catalog
elif isinstance(catalog, dict):
self._input_catalog = Catalog.from_dict(catalog) # type: ignore
self._input_catalog = Catalog.from_dict(catalog) # type: ignore[arg-type]
elif catalog is not None:
self._input_catalog = Catalog.from_dict(read_json_file(catalog))

Expand Down Expand Up @@ -490,7 +490,7 @@ def cli(

config_files.append(Path(config_path))

tap = cls( # type: ignore # Ignore 'type not callable'
tap = cls( # type: ignore[operator]
config=config_files or None,
state=state,
catalog=catalog,
Expand Down
2 changes: 1 addition & 1 deletion singer_sdk/target_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ def cli(

config_files.append(Path(config_path))

target = cls( # type: ignore # Ignore 'type not callable'
target = cls( # type: ignore[operator]
config=config_files or None,
parse_env_config=parse_env_config,
validate_config=validate_config,
Expand Down
2 changes: 1 addition & 1 deletion singer_sdk/testing/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def runner(self) -> TapTestRunner | TargetTestRunner:

for suite in test_suites:
# make sure given runner is of type TapTestRunner
expected_runner_class = ( # type: ignore[valid-type]
expected_runner_class = (
TapTestRunner
if suite.kind in {"tap", "tap_stream", "tap_stream_attribute"}
else TargetTestRunner
Expand Down
8 changes: 4 additions & 4 deletions singer_sdk/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ def __init__(self, wrapped_type: W | type[W]) -> None:
self.wrapped_type = wrapped_type

@property
def type_dict(self) -> dict: # type: ignore # OK: @classproperty vs @property
def type_dict(self) -> dict: # type: ignore[override]
"""Get type dictionary.
Returns:
Expand Down Expand Up @@ -435,7 +435,7 @@ def __init__(
self.examples = examples or None

@property
def type_dict(self) -> dict: # type: ignore # OK: @classproperty vs @property
def type_dict(self) -> dict: # type: ignore[override]
"""Get type dictionary.
Returns:
Expand Down Expand Up @@ -577,7 +577,7 @@ def __init__(
self.pattern_properties = pattern_properties

@property
def type_dict(self) -> dict: # type: ignore # OK: @classproperty vs @property
def type_dict(self) -> dict: # type: ignore[override]
"""Get type dictionary.
Returns:
Expand Down Expand Up @@ -620,7 +620,7 @@ def __init__(self, jsonschema_type_dict: dict) -> None:
self._jsonschema_type_dict = jsonschema_type_dict

@property
def type_dict(self) -> dict: # type: ignore # OK: @classproperty vs @property
def type_dict(self) -> dict: # type: ignore[override]
"""Get type dictionary.
Returns:
Expand Down

0 comments on commit 61eecbf

Please sign in to comment.