Debian Codegraph @

mesonbuild/interpreterbase/_unholder.py

raw
1 # SPDX-License-Identifier: Apache-2.0
2 # Copyright 2013-2021 The Meson development team
3
4 from __future__ import annotations
5
6 import typing as T
7
8 from .baseobjects import InterpreterObject, MesonInterpreterObject, ObjectHolder, HoldableTypes
9 from .exceptions import InvalidArguments
10 from ..mesonlib import HoldableObject, MesonBugException
11
12 if T.TYPE_CHECKING:
13 from .baseobjects import TYPE_var
14
15 def _unholder(obj: InterpreterObject) -> TYPE_var:
16 if isinstance(obj, ObjectHolder):
17 assert isinstance(obj.held_object, HoldableTypes)
18 return obj.held_object
19 elif isinstance(obj, MesonInterpreterObject):
20 return obj
21 elif isinstance(obj, HoldableObject):
22 raise MesonBugException(f'Argument {obj} of type {type(obj).__name__} is not held by an ObjectHolder.')
23 elif isinstance(obj, InterpreterObject):
24 raise InvalidArguments(f'Argument {obj} of type {type(obj).__name__} cannot be passed to a method or function')
25 raise MesonBugException(f'Unknown object {obj} of type {type(obj).__name__} in the parameters.')