diff --git a/tildes/mypy.ini b/tildes/mypy.ini index 18aa8b0..4ac6f8b 100644 --- a/tildes/mypy.ini +++ b/tildes/mypy.ini @@ -2,3 +2,4 @@ mypy_path = /opt/tildes/stubs/ disallow_untyped_defs = true ignore_missing_imports = true +no_implicit_optional = true diff --git a/tildes/tildes/models/group/group.py b/tildes/tildes/models/group/group.py index aed3f22..d970545 100644 --- a/tildes/tildes/models/group/group.py +++ b/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 diff --git a/tildes/tildes/schemas/fields.py b/tildes/tildes/schemas/fields.py index ef59e54..2f43ebd 100644 --- a/tildes/tildes/schemas/fields.py +++ b/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 diff --git a/tildes/tildes/views/user.py b/tildes/tildes/views/user.py index e7d297b..542344e 100644 --- a/tildes/tildes/views/user.py +++ b/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