Skip to content

Commit

Permalink
Merge pull request #172 from Pentusha/feature/pyright
Browse files Browse the repository at this point in the history
style: add pyright
  • Loading branch information
Pentusha authored Feb 12, 2024
2 parents 6c67abd + cc449f5 commit 25a4bff
Show file tree
Hide file tree
Showing 18 changed files with 263 additions and 221 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:

strategy:
matrix:
python-version: [ '3.10', '3.11' ]
python-version: [ '3.10', '3.11', '3.12' ]

steps:
- uses: actions/checkout@v4
Expand All @@ -36,17 +36,20 @@ jobs:

- uses: snok/[email protected]
with:
version: 1.4.0
version: 1.7.1

- name: Install dependencies
run: poetry install

- name: Run linter
- name: Run ruff
run: poetry run ruff check .

- name: Run mypy
run: poetry run mypy .

- name: Run pyright
run: poetry run pyright .

- name: Run tests
run: poetry run pytest
env:
Expand Down
4 changes: 2 additions & 2 deletions edgeql_qb/expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ def __call__(self, *columns: Union['Column', Shape]) -> Shape:
def __getattr__(self, name: str) -> 'Column':
return Column(name, self)

def __eq__(self, other: Any) -> BinaryOp: # type: ignore
def __eq__(self, other: Any) -> BinaryOp: # type: ignore[override]
return BinaryOp('=', self, other)

def __ne__(self, other: Any) -> BinaryOp: # type: ignore
def __ne__(self, other: Any) -> BinaryOp: # type: ignore[override]
return BinaryOp('!=', self, other)


Expand Down
2 changes: 1 addition & 1 deletion edgeql_qb/operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ class BinaryOp(OperationsMixin):
left: OperationsMixin
right: Union[OperationsMixin, 'SubQuery', GenericHolder[Any]]

def __eq__(self, other: Any) -> 'BinaryOp': # type: ignore
def __eq__(self, other: Any) -> 'BinaryOp': # type: ignore[override]
return BinaryOp('=', self, other)


Expand Down
2 changes: 1 addition & 1 deletion edgeql_qb/render/condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def render_filters(filters: tuple[Expression, ...], generator: Iterator[int]) ->


def render_conditions(filters: tuple[Expression, ...], generator: Iterator[int]) -> RenderedQuery:
return filters and render_filters(filters, generator) or RenderedQuery()
return render_filters(filters, generator) if filters else RenderedQuery()


@singledispatch
Expand Down
8 changes: 4 additions & 4 deletions edgeql_qb/render/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ def render_group(
RenderedQuery(f'group {model_name}')
.map(
lambda r: (
select
and combine_renderers(r, render_select_columns(select, generator))
or r
combine_renderers(r, render_select_columns(select, generator))
if select
else r
),
)
)
Expand All @@ -42,7 +42,7 @@ def render_using_expressions(
using: tuple[Expression, ...],
generator: Iterator[int],
) -> RenderedQuery:
return using and render_using(using, generator) or RenderedQuery()
return render_using(using, generator) if using else RenderedQuery()


@singledispatch
Expand Down
14 changes: 7 additions & 7 deletions edgeql_qb/render/insert.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def _(on: Column, generator: Iterator[int]) -> RenderedQuery:

@render_unless_conflict_on.register
def _(
on: tuple, # type: ignore
on: tuple, # type: ignore[type-arg]
generator: Iterator[int],
) -> RenderedQuery:
renderers = [
Expand All @@ -124,20 +124,20 @@ def _(conflict: None, generator: Iterator[int]) -> RenderedQuery:
@render_unless_conflict.register
def _(conflict: UnlessConflict, generator: Iterator[int]) -> RenderedQuery:
rendered_on = (
conflict.on
and combine_many_renderers(
combine_many_renderers(
RenderedQuery(' on '),
render_unless_conflict_on(conflict.on, generator),
)
or RenderedQuery()
if conflict.on
else RenderedQuery()
)
rendered_else = (
conflict.else_
and combine_many_renderers(
combine_many_renderers(
RenderedQuery(' else '),
render_unless_conflict_else(conflict.else_, generator),
)
or RenderedQuery()
if conflict.else_
else RenderedQuery()
)
return combine_many_renderers(
RenderedQuery(' unless conflict'),
Expand Down
2 changes: 1 addition & 1 deletion edgeql_qb/render/order_by.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def render_order_by_expressions(


def render_order_by(ordered_by: tuple[Expression, ...], generator: Iterator[int]) -> RenderedQuery:
return ordered_by and render_order_by_expressions(ordered_by, generator) or RenderedQuery()
return render_order_by_expressions(ordered_by, generator) if ordered_by else RenderedQuery()


@singledispatch
Expand Down
2 changes: 1 addition & 1 deletion edgeql_qb/render/query_literal.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def render_query_literal(value: Any, name: str) -> RenderedQuery:


@render_query_literal.register
def _(value: GenericHolder, name: str) -> RenderedQuery: # type: ignore
def _(value: GenericHolder, name: str) -> RenderedQuery: # type: ignore[type-arg]
return RenderedQuery(f'<{value.edgeql_name}>${name}', FrozenDict({name: value.value}))


Expand Down
12 changes: 6 additions & 6 deletions edgeql_qb/render/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,18 @@ def render_select(
select_from_query: SubQuery | None = None,
) -> RenderedQuery:
rendered_select = (
select_from_query
and render_parentheses(select_from_query.build(generator))
or RenderedQuery(model_name)
render_parentheses(select_from_query.build(generator))
if select_from_query
else RenderedQuery(model_name)
)
return combine_many_renderers(
RenderedQuery('select '),
rendered_select,
).map(
lambda r: (
select
and combine_renderers(r, render_select_columns(select, generator))
or r
combine_renderers(r, render_select_columns(select, generator))
if select
else r
),
)

Expand Down
2 changes: 1 addition & 1 deletion edgeql_qb/render/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def _(expression: Node, generator: Iterator[int], column_prefix: str = '') -> Re
left=render_update_expression(
expression.left,
generator,
expression.op != ':=' and '.' or '',
'.' if expression.op != ':=' else '',
),
right=render_update_expression(expression.right, generator, '.'),
expression=expression,
Expand Down
24 changes: 12 additions & 12 deletions edgeql_qb/render/with_expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,25 @@ def render_with_expressions(
) -> Callable[[RenderedQuery], RenderedQuery]:
def inner(rendered_with: RenderedQuery) -> RenderedQuery:
return (
expressions
and combine_many_renderers(
combine_many_renderers(
rendered_with,
reduce(join_renderers(', '), expressions),
)
or rendered_with
if expressions
else rendered_with
)
return inner


def render_with_module(module: str | None = None) -> Callable[[RenderedQuery], RenderedQuery]:
def inner(rendered_with: RenderedQuery) -> RenderedQuery:
return (
module
and combine_many_renderers(
combine_many_renderers(
rendered_with,
RenderedQuery(f'module {module}'),
)
or rendered_with
if module
else rendered_with
)
return inner

Expand All @@ -43,9 +43,9 @@ def render_with_separator(
def inner(rendered_with: RenderedQuery) -> RenderedQuery:
comma = RenderedQuery(', ')
return (
(module and expressions)
and combine_many_renderers(rendered_with, comma)
or rendered_with
combine_many_renderers(rendered_with, comma)
if (module and expressions)
else rendered_with
)
return inner

Expand All @@ -59,9 +59,9 @@ def inner(rendered_with: RenderedQuery) -> RenderedQuery:
space = RenderedQuery(' ')
empty = RenderedQuery()
return (
(module or expressions)
and combine_many_renderers(rendered_with, space)
or ((not module and not expressions) and empty or space)
combine_many_renderers(rendered_with, space)
if module or expressions else space
if module and expressions else empty
)
return inner

Expand Down
Loading

0 comments on commit 25a4bff

Please sign in to comment.