mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
Remove scene inclusion methods from router
The methods for including scenes as sub-routers have been removed from the router.py file. Instead, the SceneRegistry class is now set to register scenes by default upon initializing. This streamlines the scene management process by removing redundant routers and making registration automatic.
This commit is contained in:
parent
c999964f11
commit
58e9142995
2 changed files with 2 additions and 28 deletions
|
|
@ -1,15 +1,12 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from typing import Any, Dict, Final, Generator, List, Optional, Set, Type, TYPE_CHECKING
|
||||
from typing import Any, Dict, Final, Generator, List, Optional, Set
|
||||
|
||||
from .event.bases import REJECTED, UNHANDLED
|
||||
from .event.event import EventObserver
|
||||
from .event.telegram import TelegramEventObserver
|
||||
from ..types import TelegramObject
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from ..fsm.scene import Scene
|
||||
|
||||
INTERNAL_UPDATE_TYPES: Final[frozenset[str]] = frozenset({"update", "error"})
|
||||
|
||||
|
||||
|
|
@ -221,29 +218,6 @@ class Router:
|
|||
router.parent_router = self
|
||||
return router
|
||||
|
||||
def include_scenes(self, *scenes: Type[Scene], name: Optional[str] = None) -> None:
|
||||
"""
|
||||
Include multiple scenes to this router as sub-routers
|
||||
|
||||
:param scenes: scene instances
|
||||
:param name: optional name for router
|
||||
:return:
|
||||
"""
|
||||
if not scenes:
|
||||
raise ValueError("At least one scene must be provided")
|
||||
for scene in scenes:
|
||||
self.include_scene(scene, name=name)
|
||||
|
||||
def include_scene(self, scene: Type[Scene], name: Optional[str] = None) -> None:
|
||||
"""
|
||||
Include a scene to this router as sub-router
|
||||
|
||||
:param scene: scene instance
|
||||
:param name: optional name for router
|
||||
:return:
|
||||
"""
|
||||
self.include_router(scene.as_router(name=name))
|
||||
|
||||
async def emit_startup(self, *args: Any, **kwargs: Any) -> None:
|
||||
"""
|
||||
Recursively call startup callbacks
|
||||
|
|
|
|||
|
|
@ -689,7 +689,7 @@ class SceneRegistry:
|
|||
A class that represents a registry for scenes in a Telegram bot.
|
||||
"""
|
||||
|
||||
def __init__(self, router: Router, register_on_add: bool = False) -> None:
|
||||
def __init__(self, router: Router, register_on_add: bool = True) -> None:
|
||||
"""
|
||||
Initialize a new instance of the SceneRegistry class.
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue