Browse Source

Mypy: enable no_implicit_optional check

merge-requests/34/head
Chad Birch 6 years ago
parent
commit
0b4e41bd6c
  1. 1
      tildes/mypy.ini
  2. 2
      tildes/tildes/models/group/group.py
  3. 8
      tildes/tildes/schemas/fields.py
  4. 8
      tildes/tildes/views/user.py

1
tildes/mypy.ini

@ -2,3 +2,4 @@
mypy_path = /opt/tildes/stubs/
disallow_untyped_defs = true
ignore_missing_imports = true
no_implicit_optional = true

2
tildes/tildes/models/group/group.py

@ -62,7 +62,7 @@ class Group(DatabaseModel):
"""Order groups by their string representation."""
return str(self) < str(other)
def __init__(self, path: str, short_desc: str = None) -> None:
def __init__(self, path: str, short_desc: Optional[str] = None) -> None:
"""Create a new group."""
self.path = Ltree(path)
self.short_description = short_desc

8
tildes/tildes/schemas/fields.py

@ -16,7 +16,9 @@ from tildes.lib.string import simplify_string
class Enum(Field):
"""Field for a native Python Enum (or subclasses)."""
def __init__(self, enum_class: Type = None, *args: Any, **kwargs: Any) -> None:
def __init__(
self, enum_class: Optional[Type] = None, *args: Any, **kwargs: Any
) -> None:
"""Initialize the field with an optional enum class."""
super().__init__(*args, **kwargs)
self._enum_class = enum_class
@ -77,7 +79,7 @@ class Markdown(Field):
DEFAULT_MAX_LENGTH = 50_000
def __init__(self, max_length: int = None, **kwargs: Any) -> None:
def __init__(self, max_length: Optional[int] = None, **kwargs: Any) -> None:
"""Initialize the field with a length validator."""
if not max_length:
max_length = self.DEFAULT_MAX_LENGTH
@ -115,7 +117,7 @@ class SimpleString(Field):
DEFAULT_MAX_LENGTH = 200
def __init__(self, max_length: int = None, **kwargs: Any) -> None:
def __init__(self, max_length: Optional[int] = None, **kwargs: Any) -> None:
"""Initialize the field with a length validator."""
if not max_length:
max_length = self.DEFAULT_MAX_LENGTH

8
tildes/tildes/views/user.py

@ -1,6 +1,6 @@
"""Views related to a specific user."""
from typing import List, Union
from typing import List, Optional, Union
from marshmallow.fields import String
from marshmallow.validate import OneOf
@ -67,7 +67,11 @@ def _get_user_recent_activity(
{"post_type": String(load_from="type", validate=OneOf(("topic", "comment")))}
)
def get_user(
request: Request, after: str, before: str, per_page: int, post_type: str = None
request: Request,
after: str,
before: str,
per_page: int,
post_type: Optional[str] = None,
) -> dict:
"""Generate the main user history page."""
user = request.context

Loading…
Cancel
Save