summaryrefslogtreecommitdiff
path: root/src/itsdangerous/exc.py
diff options
context:
space:
mode:
authorDavid Lord <davidism@gmail.com>2020-08-27 20:19:55 -0700
committerDavid Lord <davidism@gmail.com>2020-08-31 11:48:30 -0700
commitaed5b260111c19e91af839c2c64d771c794250a0 (patch)
tree0470b53eb981133300a2d90e06500f2308745b81 /src/itsdangerous/exc.py
parentb2ac67e17e82657b38a7cd8fdcea093977bcaafc (diff)
downloaditsdangerous-aed5b260111c19e91af839c2c64d771c794250a0.tar.gz
add typing with mypy
Diffstat (limited to 'src/itsdangerous/exc.py')
-rw-r--r--src/itsdangerous/exc.py40
1 files changed, 28 insertions, 12 deletions
diff --git a/src/itsdangerous/exc.py b/src/itsdangerous/exc.py
index 8c9021d..c38a6af 100644
--- a/src/itsdangerous/exc.py
+++ b/src/itsdangerous/exc.py
@@ -1,3 +1,10 @@
+import typing as _t
+from datetime import datetime
+
+_t_opt_any = _t.Optional[_t.Any]
+_t_opt_exc = _t.Optional[Exception]
+
+
class BadData(Exception):
"""Raised if bad data of any sort was encountered. This is the base
for all exceptions that ItsDangerous defines.
@@ -5,20 +12,18 @@ class BadData(Exception):
.. versionadded:: 0.15
"""
- message = None
-
- def __init__(self, message):
+ def __init__(self, message: str):
super().__init__(message)
self.message = message
- def __str__(self):
+ def __str__(self) -> str:
return self.message
class BadSignature(BadData):
"""Raised if a signature does not match."""
- def __init__(self, message, payload=None):
+ def __init__(self, message: str, payload: _t_opt_any = None):
super().__init__(message)
#: The payload that failed the signature test. In some
@@ -26,7 +31,7 @@ class BadSignature(BadData):
#: you know it was tampered with.
#:
#: .. versionadded:: 0.14
- self.payload = payload
+ self.payload: _t_opt_any = payload
class BadTimeSignature(BadSignature):
@@ -34,7 +39,12 @@ class BadTimeSignature(BadSignature):
of :class:`BadSignature`.
"""
- def __init__(self, message, payload=None, date_signed=None):
+ def __init__(
+ self,
+ message: str,
+ payload: _t_opt_any = None,
+ date_signed: _t.Optional[datetime] = None,
+ ):
super().__init__(message, payload)
#: If the signature expired this exposes the date of when the
@@ -62,16 +72,22 @@ class BadHeader(BadSignature):
.. versionadded:: 0.24
"""
- def __init__(self, message, payload=None, header=None, original_error=None):
+ def __init__(
+ self,
+ message: str,
+ payload: _t_opt_any = None,
+ header: _t_opt_any = None,
+ original_error: _t_opt_exc = None,
+ ):
super().__init__(message, payload)
#: If the header is actually available but just malformed it
#: might be stored here.
- self.header = header
+ self.header: _t_opt_any = header
#: If available, the error that indicates why the payload was
#: not valid. This might be ``None``.
- self.original_error = original_error
+ self.original_error: _t_opt_exc = original_error
class BadPayload(BadData):
@@ -83,9 +99,9 @@ class BadPayload(BadData):
.. versionadded:: 0.15
"""
- def __init__(self, message, original_error=None):
+ def __init__(self, message: str, original_error: _t_opt_exc = None):
super().__init__(message)
#: If available, the error that indicates why the payload was
#: not valid. This might be ``None``.
- self.original_error = original_error
+ self.original_error: _t_opt_exc = original_error