Skip to content

Commit 129ad01

Browse files
committed
fixing outstanding mypy warnings
1 parent 7c4bcb9 commit 129ad01

File tree

16 files changed

+66
-44
lines changed

16 files changed

+66
-44
lines changed

piccolo/apps/app/commands/new.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import sys
44
import typing as t
55

6-
import black
6+
import black # type: ignore
77
import jinja2
88

99

piccolo/apps/asgi/commands/new.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import shutil
44
import typing as t
55

6-
import black
7-
import colorama
6+
import black # type: ignore
7+
import colorama # type: ignore
88
from jinja2 import Environment, FileSystemLoader
99

1010

piccolo/apps/migrations/commands/new.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import typing as t
77
from types import ModuleType
88

9-
import black
9+
import black # type: ignore
1010
import jinja2
1111

1212
from .base import BaseMigrationManager

piccolo/apps/playground/commands/run.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def run(
129129
Postgres port
130130
"""
131131
try:
132-
import IPython
132+
import IPython # type: ignore
133133
except ImportError:
134134
print(
135135
"Install iPython using `pip install ipython` to use this feature."
@@ -176,6 +176,6 @@ def run(
176176

177177
populate()
178178

179-
from IPython.core.interactiveshell import _asyncio_runner
179+
from IPython.core.interactiveshell import _asyncio_runner # type: ignore
180180

181181
IPython.embed(using=_asyncio_runner)

piccolo/apps/project/commands/new.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import os
33
import sys
44

5-
import black
5+
import black # type: ignore
66
import jinja2
77

88

piccolo/apps/shell/commands/run.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
def start_ipython_shell(**tables: t.Dict[str, t.Type[Table]]):
99
try:
10-
import IPython
10+
import IPython # type: ignore
1111
except ImportError:
1212
print(
1313
"Install iPython using `pip install ipython` to use this feature."
@@ -19,7 +19,7 @@ def start_ipython_shell(**tables: t.Dict[str, t.Type[Table]]):
1919
if table_class_name not in existing_global_names:
2020
globals()[table_class_name] = table_class
2121

22-
from IPython.core.interactiveshell import _asyncio_runner
22+
from IPython.core.interactiveshell import _asyncio_runner # type: ignore
2323

2424
IPython.embed(using=_asyncio_runner)
2525

piccolo/columns/defaults/timestamp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def python(self):
9090
return self.datetime
9191

9292
@classmethod
93-
def from_datetime(cls, instance: datetime.datetime):
93+
def from_datetime(cls, instance: datetime.datetime): # type: ignore
9494
return cls(
9595
year=instance.year,
9696
month=instance.month,

piccolo/conf/apps.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,10 @@ def get_table_classes(self, app_name: str) -> t.List[t.Type[Table]]:
172172
"""
173173
Returns each Table subclass defined in the given app if it exists.
174174
Otherwise raises a ValueError.
175+
176+
:raises ValueError:
177+
If an AppConfig can't be found for the given app_name.
178+
175179
"""
176180
app_config = self.get_app_config(app_name=app_name)
177181
if not app_config:
@@ -186,9 +190,12 @@ def get_table_with_name(
186190
Otherwise raises a ValueError.
187191
"""
188192
app_config = self.get_app_config(app_name=app_name)
189-
return app_config.get_table_with_name(
190-
table_class_name=table_class_name
191-
)
193+
if app_config is None:
194+
raise ValueError(f"Can't find an app_config for {app_name}")
195+
else:
196+
return app_config.get_table_with_name(
197+
table_class_name=table_class_name
198+
)
192199

193200

194201
class PiccoloConfModule(ModuleType):
@@ -270,10 +277,8 @@ def get_piccolo_conf_module(
270277
if not module_name:
271278
module_name = DEFAULT_MODULE_NAME
272279

273-
module: t.Optional[PiccoloConfModule] = None
274-
275280
try:
276-
module = import_module(module_name)
281+
module = t.cast(PiccoloConfModule, import_module(module_name))
277282
except ModuleNotFoundError:
278283
if self.diagnose:
279284
colored_warning(
@@ -284,8 +289,9 @@ def get_piccolo_conf_module(
284289
level=Level.high,
285290
)
286291
print(traceback.format_exc())
287-
288-
return module
292+
return None
293+
else:
294+
return module
289295

290296
def get_app_registry(self) -> AppRegistry:
291297
"""

piccolo/engine/postgres.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
import typing as t
77
import warnings
88

9-
import asyncpg
10-
from asyncpg.connection import Connection
11-
from asyncpg.cursor import Cursor
12-
from asyncpg.exceptions import InsufficientPrivilegeError
13-
from asyncpg.pool import Pool
9+
import asyncpg # type: ignore
10+
from asyncpg.connection import Connection # type: ignore
11+
from asyncpg.cursor import Cursor # type: ignore
12+
from asyncpg.exceptions import InsufficientPrivilegeError # type: ignore
13+
from asyncpg.pool import Pool # type: ignore
1414

1515
from piccolo.engine.base import Batch, Engine
1616
from piccolo.engine.exceptions import TransactionError

piccolo/engine/sqlite.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ async def __aexit__(self, exception_type, exception, traceback):
251251
###############################################################################
252252

253253

254-
def dict_factory(cursor, row):
254+
def dict_factory(cursor, row) -> t.Dict:
255255
d = {}
256256
for idx, col in enumerate(cursor.description):
257257
d[col[0]] = row[idx]
@@ -354,7 +354,7 @@ async def batch(self, query: Query, batch_size: int = 100) -> AsyncBatch:
354354

355355
async def get_connection(self) -> Connection:
356356
connection = await aiosqlite.connect(**self.connection_kwargs)
357-
connection.row_factory = dict_factory
357+
connection.row_factory = dict_factory # type: ignore
358358
await connection.execute("PRAGMA foreign_keys = 1")
359359
return connection
360360

@@ -366,7 +366,7 @@ async def _run_in_new_connection(
366366
async with aiosqlite.connect(**self.connection_kwargs) as connection:
367367
await connection.execute("PRAGMA foreign_keys = 1")
368368

369-
connection.row_factory = dict_factory
369+
connection.row_factory = dict_factory # type: ignore
370370
async with connection.execute(query, args) as cursor:
371371
await connection.commit()
372372
response = await cursor.fetchall()

0 commit comments

Comments
 (0)