Skip to content

Commit 8253923

Browse files
chore(error-handler): some doc and typing hints improvements
1 parent 4ef5aa2 commit 8253923

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

hydrogram/handlers/error_handler.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
# You should have received a copy of the GNU Lesser General Public License
1717
# along with Hydrogram. If not, see <http://www.gnu.org/licenses/>.
1818

19+
from __future__ import annotations
20+
21+
from collections.abc import Iterable
1922
from typing import TYPE_CHECKING, Callable
2023

2124
from .handler import Handler
@@ -29,20 +32,20 @@ class ErrorHandler(Handler):
2932
It is intended to be used with :meth:`~hydrogram.Client.add_handler`
3033
3134
For a nicer way to register this handler, have a look at the
32-
:meth:`~hydrogram.Client.on_message` decorator.
35+
:meth:`~hydrogram.Client.on_error` decorator.
3336
3437
Parameters:
3538
callback (``Callable``):
3639
Pass a function that will be called when a new Error arrives. It takes *(client, error)*
3740
as positional arguments (look at the section below for a detailed description).
3841
39-
errors (:obj:`Exception` | List of :obj:`Exception`):
42+
errors (:obj:`Exception` | List of :obj:`Exception`, *optional*):
4043
Pass one or more exception classes to allow only a subset of errors to be passed
4144
in your callback function.
4245
4346
Other parameters:
4447
client (:obj:`~hydrogram.Client`):
45-
The Client itself, useful when you want to call other API methods inside the message handler.
48+
The Client itself, useful when you want to call other API methods inside the error handler.
4649
4750
error (:obj:`~Exception`):
4851
The error that was raised.
@@ -51,16 +54,18 @@ class ErrorHandler(Handler):
5154
The update that caused the error.
5255
"""
5356

54-
def __init__(self, callback: Callable, errors=None):
57+
def __init__(
58+
self, callback: Callable, errors: type[Exception] | Iterable[type[Exception]] | None = None
59+
):
5560
if errors is None:
5661
errors = [Exception]
57-
elif not isinstance(errors, list):
62+
elif not isinstance(errors, Iterable):
5863
errors = [errors]
5964

6065
self.errors = errors
6166
super().__init__(callback)
6267

63-
async def check(self, client: "hydrogram.Client", error: Exception):
68+
async def check(self, client: hydrogram.Client, error: Exception):
6469
return any(isinstance(error, e) for e in self.errors)
6570

6671
def check_remove(self, error: Exception):

0 commit comments

Comments
 (0)