File: common.py

package info (click to toggle)
python-itemloaders 1.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 312 kB
  • sloc: python: 1,497; makefile: 78
file content (22 lines) | stat: -rw-r--r-- 677 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
"""Common functions used in Item Loaders code"""

from __future__ import annotations

from functools import partial
from typing import TYPE_CHECKING, Any

from itemloaders.utils import get_func_args

if TYPE_CHECKING:
    from collections.abc import Callable, MutableMapping


def wrap_loader_context(
    function: Callable[..., Any], context: MutableMapping[str, Any]
) -> Callable[..., Any]:
    """Wrap functions that receive loader_context to contain the context
    "pre-loaded" and expose a interface that receives only one argument
    """
    if "loader_context" in get_func_args(function):
        return partial(function, loader_context=context)
    return function