def __getitem__(self, source):
        """Get the ``Source`` instance for the given source class.

        Arguments
        ---------
        source : object
            The source to fetch in the registry dictionary.
            It may be an instance of a class, in which case its class will be used.
            It may be a subclass of a class in the registry, and if this one was registered
            with ``allow_subclasses`` set to ``True``, this class will be used.

        Returns
        -------
        Source
            The ``Source`` instance from the registry that matches the given source.

        Raises
        ------
        dataql.solvers.exceptions.SourceNotFound
            If the given source is not in the registry.

        Example
        -------

        >>> from datetime import date, datetime
        >>> registry = Registry()
        >>> registry.register(date, ['year', 'month', 'day'])
        >>> registry[date]
        <Source 'datetime.date'>
        >>> registry[date.today()]
        <Source 'datetime.date'>
        >>> registry[datetime]
        <Source 'datetime.date'>
        >>> registry = Registry()
        >>> registry.register(date, ['year', 'month', 'day'],allow_subclasses=False)
        >>> registry[datetime] # doctest: +ELLIPSIS
        Traceback (most recent call last):
        dataql.solvers.exceptions.SourceNotFound: The `datetime.datetime` source is not...

        """

        # Get the class if the source is an instance.
        if not isinstance(source, type):
            source = source.__class__

        # Best case: we have the source itself, so we return it.
        if source in self.sources:
            return self.sources[source]

        # We don't have the source, we try to get one of its ancestors (only ancestors that
        # allow subclasses)
        for klass in source.mro()[1:]:  # "1:" to avoid using the source main class
            try:
                result = self.sources[klass]
            except KeyError:
                continue
            else:
                if result.allow_subclasses:
                    return result

        # Not found, return the default error of a ``__getitem__`` method.
        raise SourceNotFound(self, source)
def __getitem__ ( self , source ) : if not isinstance ( source , type ) : source = source . __class__ if source in self . sources : return self . sources [ source ] for klass in source . mro ( ) [ 1 : ] : try : result = self . sources [ klass ] except KeyError : continue else : if result . allow_subclasses : return result raise SourceNotFound ( self , source )
Get the ``Source`` instance for the given source class.

        Arguments
        ---------
        source : object
            The source to fetch in the registry dictionary.
            It may be an instance of a class, in which case its class will be used.
            It may be a subclass of a class in the registry, and if this one was registered
            with ``allow_subclasses`` set to ``True``, this class will be used.

        Returns
        -------
        Source
            The ``Source`` instance from the registry that matches the given source.

        Raises
        ------
        dataql.solvers.exceptions.SourceNotFound
            If the given source is not in the registry.

        Example
        -------

        >>> from datetime import date, datetime
        >>> registry = Registry()
        >>> registry.register(date, ['year', 'month', 'day'])
        >>> registry[date]
        <Source 'datetime.date'>
        >>> registry[date.today()]
        <Source 'datetime.date'>
        >>> registry[datetime]
        <Source 'datetime.date'>
        >>> registry = Registry()
        >>> registry.register(date, ['year', 'month', 'day'],allow_subclasses=False)
        >>> registry[datetime] # doctest: +ELLIPSIS
        Traceback (most recent call last):
        dataql.solvers.exceptions.SourceNotFound: The `datetime.datetime` source is not...