Format: text/x-python
⬇ Download File (1.2 KB)
   1  '''
   2  Decorators are not really values, however we need some wrappers to improve
   3  docstrings and other things around decorators.
   4  '''
   5  
   6  from jedi.inference.base_value import ValueWrapper, ValueSet
   7  
   8  
   9  class Decoratee(ValueWrapper):
  10      def __init__(self, wrapped_value, original_value):
  11          super().__init__(wrapped_value)
  12          self._original_value = original_value
  13  
  14      def py__doc__(self):
  15          return self._original_value.py__doc__()
  16  
  17      def py__get__(self, instance, class_value):
  18          return ValueSet(
  19              Decoratee(v, self._original_value)
  20              for v in self._wrapped_value.py__get__(instance, class_value)
  21          )
  22  
  23      def get_signatures(self):
  24          signatures = self._wrapped_value.get_signatures()
  25          if signatures:
  26              return signatures
  27          # Fallback to signatures of the original function/class if the
  28          # decorator has no signature or it is not inferrable.
  29          #
  30          # __get__ means that it's a descriptor. In that case we don't return
  31          # signatures, because they are usually properties.
  32          if not self._wrapped_value.py__getattribute__('__get__'):
  33              return self._original_value.get_signatures()
  34          return []
  35