Skip to content

Commit c951425

Browse files
authored
Merge pull request piccolo-orm#20 from piccolo-orm/mypy_fixes
Mypy fixes
2 parents 989ad3d + 866211d commit c951425

File tree

18 files changed

+68
-45
lines changed

18 files changed

+68
-45
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ before_script:
2121
- psql -c "CREATE EXTENSION IF NOT EXISTS \"uuid-ossp\";" -d piccolo -U postgres
2222
script:
2323
- flake8 piccolo
24+
- mypy piccolo
2425
- cd tests && ./travis.sh
2526
after_success:
2627
- cd .. && coveralls

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

0 commit comments

Comments
 (0)