diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-07-18 14:13:18 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-07-18 14:13:18 -0400 |
commit | dff7c2ad2c913ed0ec5979ff9470dd5dd5813483 (patch) | |
tree | 6f1c6483f8bac9ac68820984ae9a3f8137e418b0 /lib/sqlalchemy/inspection.py | |
parent | 643a9afa86328ca6038d00543700dbe0f51af5e6 (diff) | |
download | sqlalchemy-dff7c2ad2c913ed0ec5979ff9470dd5dd5813483.tar.gz |
- document the inspection system
Diffstat (limited to 'lib/sqlalchemy/inspection.py')
-rw-r--r-- | lib/sqlalchemy/inspection.py | 48 |
1 files changed, 40 insertions, 8 deletions
diff --git a/lib/sqlalchemy/inspection.py b/lib/sqlalchemy/inspection.py index 8b0a751ad..34a47217b 100644 --- a/lib/sqlalchemy/inspection.py +++ b/lib/sqlalchemy/inspection.py @@ -4,22 +4,54 @@ # This module is part of SQLAlchemy and is released under # the MIT License: http://www.opensource.org/licenses/mit-license.php -"""Base inspect API. +"""The inspection module provides the :func:`.inspect` function, +which delivers runtime information about a wide variety +of SQLAlchemy objects, both within the Core as well as the +ORM. -:func:`.inspect` provides access to a contextual object -regarding a subject. +The :func:`.inspect` function is the entry point to SQLAlchemy's +public API for viewing the configuration and construction +of in-memory objects. Depending on the type of object +passed to :func:`.inspect`, the return value will either be +a related object which provides a known interface, or in many +cases it will return the object itself. + +The rationale for :func:`.inspect` is twofold. One is that +it replaces the need to be aware of a large variety of "information +getting" functions in SQLAlchemy, such as :meth:`.Inspector.from_engine`, +:func:`.orm.attributes.instance_state`, :func:`.orm.class_mapper`, +and others. The other is that the return value of :func:`.inspect` +is guaranteed to obey a documented API, thus allowing third party +tools which build on top of SQLAlchemy configurations to be constructed +in a forwards-compatible way. + +.. versionadded:: 0.8 The :func:`.inspect` system is introduced + as of version 0.8. -Various subsections of SQLAlchemy, -such as the :class:`.Inspector`, :class:`.Mapper`, and -others register themselves with the "inspection registry" here -so that they may return a context object given a certain kind -of argument. """ from . import util, exc _registrars = util.defaultdict(list) def inspect(subject, raiseerr=True): + """Produce an inspection object for the given target. + + The returned value in some cases may be the + same object as the one given, such as if a + :class:`.orm.Mapper` object is passed. In other + cases, it will be an instance of the registered + inspection type for the given object, such as + if a :class:`.engine.Engine` is passed, an + :class:`.engine.Inspector` object is returned. + + :param subject: the subject to be inspected. + :param raiseerr: When ``True``, if the given subject + does not + correspond to a known SQLAlchemy inspected type, + :class:`sqlalchemy.exc.NoInspectionAvailable` + is raised. If ``False``, ``None`` is returned. + + """ type_ = type(subject) for cls in type_.__mro__: if cls in _registrars: |