Skip to content

Commit 227b9f7

Browse files
committed
Fixes on locate
1 parent d047332 commit 227b9f7

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

setup.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = telegrambots-custom
3-
version = 0.0.7rc2
3+
version = 0.0.7rc3
44
author = immmdreza
55
author_email = [email protected]
66
description = A custom extension packages for telegrambots.

src/telegrambots/custom/extensions/dispatcher.py

+11-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import importlib
22
import inspect
3+
import logging
34
import os
45
from abc import ABC
56
from pathlib import Path
@@ -17,6 +18,13 @@
1718
if TYPE_CHECKING:
1819
from .. import Dispatcher
1920

21+
logging.basicConfig(
22+
format="%(asctime)s %(message)s",
23+
datefmt="%m/%d/%Y %I:%M:%S %p",
24+
level=logging.INFO,
25+
)
26+
dispatcher_logger = logging.getLogger("telegrambots.dispatcher")
27+
2028

2129
class DispatcherExtensions(ABC):
2230
def __init__(self, dp: "Dispatcher") -> None:
@@ -254,16 +262,14 @@ def locate(self, path: Path):
254262
try:
255263
module = importlib.import_module(module_name)
256264

257-
for name, obj in inspect.getmembers(module, inspect.isclass):
265+
for _, obj in inspect.getmembers(module, inspect.isclass):
258266
if issubclass(obj, AbstractHandler):
259267
if not inspect.isabstract(obj):
260268
instance: AbstractHandler[Any, Any] = obj() # type: ignore
261269
instance.set_dp(self._dp)
262270
self._dp.add_handler(instance)
263-
264-
yield name
265-
266-
except ImportError:
271+
except ImportError as e:
272+
dispatcher_logger.error(f"Failed to import module {module_name}: {e}")
267273
continue
268274

269275

0 commit comments

Comments
 (0)