Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Use Ruff to format docstrings #2104

Merged
merged 1 commit into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
1 change: 0 additions & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ def mypy(session: Session) -> None:
"mypy",
"pytest",
"importlib-resources",
"sqlalchemy2-stubs",
"types-jsonschema",
"types-python-dateutil",
"types-pytz",
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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/*",
Expand Down
12 changes: 6 additions & 6 deletions singer_sdk/authenticators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 5 additions & 5 deletions singer_sdk/connectors/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
Expand All @@ -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,
Expand Down Expand Up @@ -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(
Expand Down
36 changes: 12 additions & 24 deletions singer_sdk/helpers/_flattening.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,7 @@ def flatten_schema(
>>> schema = {
... "type": "object",
... "properties": {
... "id": {
... "type": "string"
... },
... "id": {"type": "string"},
... "foo": {
... "type": "object",
... "properties": {
Expand All @@ -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))
{
Expand Down Expand Up @@ -189,9 +183,7 @@ def flatten_schema(
>>> nullable_leaves_schema = {
... "type": "object",
... "properties": {
... "id": {
... "type": "string"
... },
... "id": {"type": "string"},
... "foo": {
... "type": ["object", "null"],
... "properties": {
Expand All @@ -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))
{
Expand Down
3 changes: 2 additions & 1 deletion singer_sdk/pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions singer_sdk/streams/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)"}
Expand Down
20 changes: 10 additions & 10 deletions singer_sdk/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()