Skip to content

Commit 9dce556

Browse files
authored
Merge pull request #73 from python-ellar/mypy_fix_3oct
fix: Mypy and Ruff Errors
2 parents cea555a + 370134e commit 9dce556

File tree

15 files changed

+73
-48
lines changed

15 files changed

+73
-48
lines changed

.github/workflows/publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
- name: Set up Python
1414
uses: actions/setup-python@v5
1515
with:
16-
python-version: 3.8
16+
python-version: '3.12'
1717
- name: Install Flit
1818
run: pip install flit
1919
- name: Install Dependencies

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
- name: Set up Python
1515
uses: actions/setup-python@v5
1616
with:
17-
python-version: 3.8
17+
python-version: '3.12'
1818
- name: Install Flit
1919
run: pip install flit
2020
- name: Install Dependencies

.github/workflows/test_full.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
runs-on: ubuntu-latest
1111
strategy:
1212
matrix:
13-
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
13+
python-version: ['3.10', '3.11', '3.12', '3.13']
1414

1515
steps:
1616
- uses: actions/checkout@v4
@@ -32,7 +32,7 @@ jobs:
3232
- name: Set up Python
3333
uses: actions/setup-python@v5
3434
with:
35-
python-version: 3.8
35+
python-version: '3.12'
3636
- name: Install Flit
3737
run: pip install flit
3838
- name: Install Dependencies

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ help:
55
@fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
66

77
clean: ## Removing cached python compiled files
8-
find . -name \*pyc | xargs rm -fv
9-
find . -name \*pyo | xargs rm -fv
10-
find . -name \*~ | xargs rm -fv
8+
find . -name "*.pyc" -type f -delete
9+
find . -name "*.pyo" -type f -delete
10+
find . -name "*~" -type f -delete
1111
find . -name __pycache__ | xargs rm -rfv
1212
find . -name .pytest_cache | xargs rm -rfv
1313
find . -name .ruff_cache | xargs rm -rfv

docs/multiple/index.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,23 @@ EllarSQLModule.setup(
2828
)
2929
```
3030

31+
## **Configuring Async Databases**
32+
When configuring async databases,
33+
you need to specify the `+asyncpg` or `+aiosqlite` suffix to the database URL in case of SQLite and PostgreSQL respectively.
34+
35+
For example, to configure an async database, you can use the following configuration:
36+
```python
37+
from ellar_sql import EllarSQLModule
38+
39+
EllarSQLModule.setup(
40+
databases={
41+
"default": "postgresql+asyncpg:///main",
42+
"meta": "sqlite+aiosqlite:////path/to/meta.db",
43+
},
44+
migration_options={'directory': 'migrations'}
45+
)
46+
```
47+
3148
## **Defining Models and Tables with Different Databases**
3249

3350
**EllarSQL** creates **Metadata** and an **Engine** for each configured database.

ellar_sql/cli/commands.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ def db():
3636
@click.option(
3737
"--sql",
3838
is_flag=True,
39-
help="Don't emit SQL to database - dump to standard output " "instead",
39+
help="Don't emit SQL to database - dump to standard output instead",
4040
)
4141
@click.option(
4242
"--head",
4343
default="head",
44-
help="Specify head revision or <branchname>@head to base new " "revision on",
44+
help="Specify head revision or <branchname>@head to base new revision on",
4545
)
4646
@click.option(
4747
"--splice",
@@ -61,7 +61,7 @@ def db():
6161
@click.option(
6262
"--rev-id",
6363
default=None,
64-
help="Specify a hardcoded revision id instead of generating " "one",
64+
help="Specify a hardcoded revision id instead of generating one",
6565
)
6666
@click.pass_context
6767
def revision(
@@ -102,12 +102,12 @@ def revision(
102102
@click.option(
103103
"--sql",
104104
is_flag=True,
105-
help="Don't emit SQL to database - dump to standard output " "instead",
105+
help="Don't emit SQL to database - dump to standard output instead",
106106
)
107107
@click.option(
108108
"--head",
109109
default="head",
110-
help="Specify head revision or <branchname>@head to base new " "revision on",
110+
help="Specify head revision or <branchname>@head to base new revision on",
111111
)
112112
@click.option(
113113
"--splice",
@@ -127,7 +127,7 @@ def revision(
127127
@click.option(
128128
"--rev-id",
129129
default=None,
130-
help="Specify a hardcoded revision id instead of generating " "one",
130+
help="Specify a hardcoded revision id instead of generating one",
131131
)
132132
@click.option(
133133
"-x",
@@ -195,7 +195,7 @@ def edit(ctx, directory, revision):
195195
@click.option(
196196
"--rev-id",
197197
default=None,
198-
help="Specify a hardcoded revision id instead of generating " "one",
198+
help="Specify a hardcoded revision id instead of generating one",
199199
)
200200
@click.argument("revisions", nargs=-1)
201201
@click.pass_context
@@ -215,12 +215,12 @@ def merge(ctx, directory, message, branch_label, rev_id, revisions):
215215
@click.option(
216216
"--sql",
217217
is_flag=True,
218-
help="Don't emit SQL to database - dump to standard output " "instead",
218+
help="Don't emit SQL to database - dump to standard output instead",
219219
)
220220
@click.option(
221221
"--tag",
222222
default=None,
223-
help='Arbitrary "tag" name - can be used by custom env.py ' "scripts",
223+
help='Arbitrary "tag" name - can be used by custom env.py scripts',
224224
)
225225
@click.option(
226226
"-x",
@@ -246,12 +246,12 @@ def upgrade(ctx, directory, sql, tag, x_arg, revision):
246246
@click.option(
247247
"--sql",
248248
is_flag=True,
249-
help="Don't emit SQL to database - dump to standard output " "instead",
249+
help="Don't emit SQL to database - dump to standard output instead",
250250
)
251251
@click.option(
252252
"--tag",
253253
default=None,
254-
help='Arbitrary "tag" name - can be used by custom env.py ' "scripts",
254+
help='Arbitrary "tag" name - can be used by custom env.py scripts',
255255
)
256256
@click.option(
257257
"-x",
@@ -300,7 +300,7 @@ def show(ctx: click.Context, directory, revision):
300300
"-i",
301301
"--indicate-current",
302302
is_flag=True,
303-
help="Indicate current version (Alembic 0.9.9 or greater is " "required)",
303+
help="Indicate current version (Alembic 0.9.9 or greater is required)",
304304
)
305305
@click.pass_context
306306
def history(ctx: click.Context, directory, rev_range, verbose, indicate_current):
@@ -369,12 +369,12 @@ def current(ctx: click.Context, directory, verbose):
369369
@click.option(
370370
"--sql",
371371
is_flag=True,
372-
help="Don't emit SQL to database - dump to standard output " "instead",
372+
help="Don't emit SQL to database - dump to standard output instead",
373373
)
374374
@click.option(
375375
"--tag",
376376
default=None,
377-
help='Arbitrary "tag" name - can be used by custom env.py ' "scripts",
377+
help='Arbitrary "tag" name - can be used by custom env.py scripts',
378378
)
379379
@click.argument("revision", default="head")
380380
@click.pass_context
@@ -416,7 +416,7 @@ def check(ctx: click.Context, directory):
416416
@click.option(
417417
"--package",
418418
is_flag=True,
419-
help="Write empty __init__.py files to the environment and " "version locations",
419+
help="Write empty __init__.py files to the environment and version locations",
420420
)
421421
@click.pass_context
422422
def init(ctx: click.Context, directory, multiple, package):

ellar_sql/factory/base.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919

2020

2121
class EllarSQLOptions(SQLAlchemyOptions):
22+
# Type hints for SQLAlchemy-specific attributes
23+
sqlalchemy_get_or_create: t.Tuple[str, ...]
24+
sqlalchemy_session_persistence: str
25+
2226
@staticmethod
2327
def _check_has_sqlalchemy_session_set(meta, value):
2428
if value and hasattr(meta, "sqlalchemy_session"):
@@ -31,6 +35,7 @@ class EllarSQLFactory(SQLAlchemyModelFactory):
3135
"""Factory for EllarSQL models."""
3236

3337
_options_class = EllarSQLOptions
38+
_meta: EllarSQLOptions
3439

3540
class Meta:
3641
abstract = True

ellar_sql/model/base.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ def __new__(
6262
)
6363
if isinstance(options, dict):
6464
options = ModelBaseConfig(**options)
65-
assert isinstance(
66-
options, ModelBaseConfig
67-
), f"{options.__class__} is not a support ModelMetaOptions"
65+
assert isinstance(options, ModelBaseConfig), (
66+
f"{options.__class__} is not a support ModelMetaOptions"
67+
)
6868

6969
if options.as_base:
7070
declarative_bases = _get_declarative_bases(options.use_bases)

ellar_sql/model/typeDecorator/file/file.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@ class File(BaseFile, AttributeDictAccessMixin):
4848

4949
files: t.List[str]
5050

51+
# Type hints for dict-like methods from parent classes
52+
if t.TYPE_CHECKING:
53+
54+
def get(self, __key: str, __default: t.Any = None) -> t.Any: ...
55+
56+
def __setitem__(self, __key: str, __value: t.Any) -> None: ...
57+
58+
def __getitem__(self, __key: str) -> t.Any: ...
59+
5160
def __init__(
5261
self,
5362
content: t.Any = None,

ellar_sql/pagination/decorator.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ def _prepare_template_response(
7474
]:
7575
if isinstance(res, tuple):
7676
filter_query, extra_context = res
77-
assert isinstance(
78-
extra_context, dict
79-
), "When using as `template_context`, route function should return a tuple(select, {})"
77+
assert isinstance(extra_context, dict), (
78+
"When using as `template_context`, route function should return a tuple(select, {})"
79+
)
8080

8181
elif isinstance(res, dict):
8282
filter_query = None

0 commit comments

Comments
 (0)