summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm/events.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sqlalchemy/orm/events.py')
-rw-r--r--lib/sqlalchemy/orm/events.py13
1 files changed, 10 insertions, 3 deletions
diff --git a/lib/sqlalchemy/orm/events.py b/lib/sqlalchemy/orm/events.py
index c531e7cf1..331c224ee 100644
--- a/lib/sqlalchemy/orm/events.py
+++ b/lib/sqlalchemy/orm/events.py
@@ -11,6 +11,9 @@
from __future__ import annotations
from typing import Any
+from typing import Optional
+from typing import Type
+from typing import TYPE_CHECKING
import weakref
from . import instrumentation
@@ -27,6 +30,10 @@ from .. import exc
from .. import util
from ..util.compat import inspect_getfullargspec
+if TYPE_CHECKING:
+ from ._typing import _O
+ from .instrumentation import ClassManager
+
class InstrumentationEvents(event.Events):
"""Events related to class instrumentation events.
@@ -214,7 +221,7 @@ class InstanceEvents(event.Events):
if issubclass(target, mapperlib.Mapper):
return instrumentation.ClassManager
else:
- manager = instrumentation.manager_of_class(target)
+ manager = instrumentation.opt_manager_of_class(target)
if manager:
return manager
else:
@@ -613,8 +620,8 @@ class _EventsHold(event.RefCollection):
class _InstanceEventsHold(_EventsHold):
all_holds = weakref.WeakKeyDictionary()
- def resolve(self, class_):
- return instrumentation.manager_of_class(class_)
+ def resolve(self, class_: Type[_O]) -> Optional[ClassManager[_O]]:
+ return instrumentation.opt_manager_of_class(class_)
class HoldInstanceEvents(_EventsHold.HoldEvents, InstanceEvents):
pass