File: decorator.py

package info (click to toggle)
python-jedi 0.18.2-1
  • links: PTS
  • area: main
  • in suites: bookworm
  • size: 11,660 kB
  • sloc: python: 28,554; makefile: 172; ansic: 13
file content (34 lines) | stat: -rw-r--r-- 1,207 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
'''
Decorators are not really values, however we need some wrappers to improve
docstrings and other things around decorators.
'''

from jedi.inference.base_value import ValueWrapper, ValueSet


class Decoratee(ValueWrapper):
    def __init__(self, wrapped_value, original_value):
        super().__init__(wrapped_value)
        self._original_value = original_value

    def py__doc__(self):
        return self._original_value.py__doc__()

    def py__get__(self, instance, class_value):
        return ValueSet(
            Decoratee(v, self._original_value)
            for v in self._wrapped_value.py__get__(instance, class_value)
        )

    def get_signatures(self):
        signatures = self._wrapped_value.get_signatures()
        if signatures:
            return signatures
        # Fallback to signatures of the original function/class if the
        # decorator has no signature or it is not inferrable.
        #
        # __get__ means that it's a descriptor. In that case we don't return
        # signatures, because they are usually properties.
        if not self._wrapped_value.py__getattribute__('__get__'):
            return self._original_value.get_signatures()
        return []