From b3d43df4985d6344d1568870e0116055566a0ffc Mon Sep 17 00:00:00 2001 From: jkiely Date: Thu, 17 May 2018 10:58:58 -0400 Subject: [PATCH] mypy: Enable strict optional for lib/exceptions. Change return type of reduce_ex to pass under stricter conditions. --- mypy.ini | 2 +- zerver/lib/exceptions.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/mypy.ini b/mypy.ini index 54f572c3c9..a4b48ea25a 100644 --- a/mypy.ini +++ b/mypy.ini @@ -316,7 +316,7 @@ strict_optional = False [mypy-zerver.lib.events] # signup_notifications_stream is Optional, but accessing id property strict_optional = True [mypy-zerver.lib.exceptions] #21: error: Return type of "__reduce_ex__" incompatible with supertype "object" -strict_optional = False +strict_optional = True [mypy-zerver.lib.bugdown.api_arguments_table_generator] #18: error: Item "None" of "Optional[Dict[str, Any]]" has no attribute "items" strict_optional = False [mypy-zerver.lib.message] #868: error: Unsupported operand types for - ("Optional[int]" and "int") diff --git a/zerver/lib/exceptions.py b/zerver/lib/exceptions.py index 9b6b716be8..7ce202bfe3 100644 --- a/zerver/lib/exceptions.py +++ b/zerver/lib/exceptions.py @@ -1,5 +1,6 @@ from enum import Enum from typing import Any, Dict, List, Optional, Type +from mypy_extensions import NoReturn from django.core.exceptions import PermissionDenied from django.utils.translation import ugettext as _ @@ -20,7 +21,7 @@ class AbstractEnum(Enum): def value(self) -> None: raise AssertionError("Not implemented") - def __reduce_ex__(self, proto: int) -> None: + def __reduce_ex__(self, proto: int) -> NoReturn: raise AssertionError("Not implemented") class ErrorCode(AbstractEnum):