From 76625a81db8df02eafacd56d6e1313d32e3e7aa1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edgar=20Ram=C3=ADrez=20Mondrag=C3=B3n?= <16805946+edgarrmondragon@users.noreply.github.com> Date: Wed, 13 Dec 2023 20:53:39 -0600 Subject: [PATCH] chore: Use Ruff to format docstrings (#2104) --- .pre-commit-config.yaml | 2 +- noxfile.py | 1 - pyproject.toml | 3 +++ singer_sdk/authenticators.py | 12 +++++------ singer_sdk/connectors/sql.py | 10 ++++----- singer_sdk/helpers/_flattening.py | 36 +++++++++++-------------------- singer_sdk/pagination.py | 3 ++- singer_sdk/streams/rest.py | 1 + singer_sdk/typing.py | 20 ++++++++--------- 9 files changed, 40 insertions(+), 48 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 912de8743..138a9e9e1 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -45,7 +45,7 @@ repos: - id: check-readthedocs - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.1.7 + rev: v0.1.8 hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix, --show-fixes] diff --git a/noxfile.py b/noxfile.py index 8f66a14c7..54c58fa58 100644 --- a/noxfile.py +++ b/noxfile.py @@ -68,7 +68,6 @@ def mypy(session: Session) -> None: "mypy", "pytest", "importlib-resources", - "sqlalchemy2-stubs", "types-jsonschema", "types-python-dateutil", "types-pytz", diff --git a/pyproject.toml b/pyproject.toml index bb7815fe1..7e5de9ba9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -245,6 +245,9 @@ line-length = 88 src = ["samples", "singer_sdk", "tests"] target-version = "py37" +[tool.ruff.format] +docstring-code-format = true + [tool.ruff.lint] exclude = [ "cookiecutter/*", diff --git a/singer_sdk/authenticators.py b/singer_sdk/authenticators.py index 8336c68a8..d31ab1dee 100644 --- a/singer_sdk/authenticators.py +++ b/singer_sdk/authenticators.py @@ -443,12 +443,12 @@ def oauth_request_body(self) -> dict: @property def oauth_request_body(self) -> dict: return { - 'grant_type': 'password', - 'scope': 'https://api.powerbi.com', - 'resource': 'https://analysis.windows.net/powerbi/api', - 'client_id': self.config["client_id"], - 'username': self.config.get("username", self.config["client_id"]), - 'password': self.config["password"], + "grant_type": "password", + "scope": "https://api.powerbi.com", + "resource": "https://analysis.windows.net/powerbi/api", + "client_id": self.config["client_id"], + "username": self.config.get("username", self.config["client_id"]), + "password": self.config["password"], } Raises: diff --git a/singer_sdk/connectors/sql.py b/singer_sdk/connectors/sql.py index c4ddba880..5f61908e7 100644 --- a/singer_sdk/connectors/sql.py +++ b/singer_sdk/connectors/sql.py @@ -444,8 +444,10 @@ def discover_catalog_entry( if pk_def and "constrained_columns" in pk_def: possible_primary_keys.append(pk_def["constrained_columns"]) + # An element of the columns list is ``None`` if it's an expression and is + # returned in the ``expressions`` list of the reflected index. possible_primary_keys.extend( - index_def["column_names"] + index_def["column_names"] # type: ignore[misc] for index_def in inspected.get_indexes(table_name, schema=schema_name) if index_def.get("unique", False) ) @@ -457,9 +459,7 @@ def discover_catalog_entry( for column_def in inspected.get_columns(table_name, schema=schema_name): column_name = column_def["name"] is_nullable = column_def.get("nullable", False) - jsonschema_type: dict = self.to_jsonschema_type( - t.cast(sqlalchemy.types.TypeEngine, column_def["type"]), - ) + jsonschema_type: dict = self.to_jsonschema_type(column_def["type"]) table_schema.append( th.Property( name=column_name, @@ -979,7 +979,7 @@ def _get_column_type( msg = f"Column `{column_name}` does not exist in table `{full_table_name}`." raise KeyError(msg) from ex - return t.cast(sqlalchemy.types.TypeEngine, column.type) + return column.type @staticmethod def get_column_add_ddl( diff --git a/singer_sdk/helpers/_flattening.py b/singer_sdk/helpers/_flattening.py index 3cf1f172e..866eb8a48 100644 --- a/singer_sdk/helpers/_flattening.py +++ b/singer_sdk/helpers/_flattening.py @@ -96,9 +96,7 @@ def flatten_schema( >>> schema = { ... "type": "object", ... "properties": { - ... "id": { - ... "type": "string" - ... }, + ... "id": {"type": "string"}, ... "foo": { ... "type": "object", ... "properties": { @@ -107,17 +105,13 @@ def flatten_schema( ... "properties": { ... "baz": { ... "type": "object", - ... "properties": { - ... "qux": { - ... "type": "string" - ... } - ... } + ... "properties": {"qux": {"type": "string"}}, ... } - ... } + ... }, ... } - ... } - ... } - ... } + ... }, + ... }, + ... }, ... } >>> print(json.dumps(flatten_schema(schema, 0), indent=2)) { @@ -189,9 +183,7 @@ def flatten_schema( >>> nullable_leaves_schema = { ... "type": "object", ... "properties": { - ... "id": { - ... "type": "string" - ... }, + ... "id": {"type": "string"}, ... "foo": { ... "type": ["object", "null"], ... "properties": { @@ -200,17 +192,13 @@ def flatten_schema( ... "properties": { ... "baz": { ... "type": ["object", "null"], - ... "properties": { - ... "qux": { - ... "type": "string" - ... } - ... } + ... "properties": {"qux": {"type": "string"}}, ... } - ... } + ... }, ... } - ... } - ... } - ... } + ... }, + ... }, + ... }, ... } >>> print(json.dumps(flatten_schema(nullable_leaves_schema, 0), indent=2)) { diff --git a/singer_sdk/pagination.py b/singer_sdk/pagination.py index f00bb0920..238740768 100644 --- a/singer_sdk/pagination.py +++ b/singer_sdk/pagination.py @@ -30,7 +30,7 @@ def first(iterable: t.Iterable[T]) -> T: Returns: The first element of the iterable. - >>> first('ABC') + >>> first("ABC") 'A' """ return next(iter(iterable)) @@ -205,6 +205,7 @@ class MyHATEOASPaginator(BaseHATEOASPaginator): def get_next_url(self, response): return response.json().get("next") + class MyStream(Stream): def get_new_paginator(self): return MyHATEOASPaginator() diff --git a/singer_sdk/streams/rest.py b/singer_sdk/streams/rest.py index 378b32c73..570508207 100644 --- a/singer_sdk/streams/rest.py +++ b/singer_sdk/streams/rest.py @@ -292,6 +292,7 @@ def get_url_params( from urllib.parse import urlencode + class MyStream(RESTStream): def get_url_params(self, context, next_page_token): params = {"key": "(a,b,c)"} diff --git a/singer_sdk/typing.py b/singer_sdk/typing.py index 37c1f40c1..657628a9b 100644 --- a/singer_sdk/typing.py +++ b/singer_sdk/typing.py @@ -1013,26 +1013,26 @@ def to_sql_type( # noqa: PLR0911, C901 datelike_type = get_datelike_property_type(jsonschema_type) if datelike_type: if datelike_type == "date-time": - return t.cast(sqlalchemy.types.TypeEngine, sqlalchemy.types.DATETIME()) + return sqlalchemy.types.DATETIME() if datelike_type in "time": - return t.cast(sqlalchemy.types.TypeEngine, sqlalchemy.types.TIME()) + return sqlalchemy.types.TIME() if datelike_type == "date": - return t.cast(sqlalchemy.types.TypeEngine, sqlalchemy.types.DATE()) + return sqlalchemy.types.DATE() maxlength = jsonschema_type.get("maxLength") - return t.cast(sqlalchemy.types.TypeEngine, sqlalchemy.types.VARCHAR(maxlength)) + return sqlalchemy.types.VARCHAR(maxlength) if _jsonschema_type_check(jsonschema_type, ("integer",)): - return t.cast(sqlalchemy.types.TypeEngine, sqlalchemy.types.INTEGER()) + return sqlalchemy.types.INTEGER() if _jsonschema_type_check(jsonschema_type, ("number",)): - return t.cast(sqlalchemy.types.TypeEngine, sqlalchemy.types.DECIMAL()) + return sqlalchemy.types.DECIMAL() if _jsonschema_type_check(jsonschema_type, ("boolean",)): - return t.cast(sqlalchemy.types.TypeEngine, sqlalchemy.types.BOOLEAN()) + return sqlalchemy.types.BOOLEAN() if _jsonschema_type_check(jsonschema_type, ("object",)): - return t.cast(sqlalchemy.types.TypeEngine, sqlalchemy.types.VARCHAR()) + return sqlalchemy.types.VARCHAR() if _jsonschema_type_check(jsonschema_type, ("array",)): - return t.cast(sqlalchemy.types.TypeEngine, sqlalchemy.types.VARCHAR()) + return sqlalchemy.types.VARCHAR() - return t.cast(sqlalchemy.types.TypeEngine, sqlalchemy.types.VARCHAR()) + return sqlalchemy.types.VARCHAR()