Example #1
0
    def __init__(self, text, info=[]):
        '''Gives the ability to add information about the docstring.

        One bit of info that is useful to know is if the docstring is a class.
        PEP257 requires that classes have a one-line upper and lower margin.

        Args:
            text ()
            info (list)

        '''
        super(DocstringPep257, self) .__init__(text)
        self.serialized.update({self.get_rule_name(x[0]): {} for x
            in inspect.getmembers(self, predicate=inspect.ismethod)})
        self.info = info
        self.serialized['info'] = self.info
        self.serialized['origText'] = text
        self.serialized['origLineText'] = text.split('\n')
        self.serialized['fixLines'] = defaultdict(list)
        docStart, docEnd = \
                docstring.crop_to_docstring(self.serialized['origText'])
        self.serialized['bounds'] = (0, -1)

        if not self.is_style():
            raise ValueError('text: {!r} is not a valid docstring type: '
                             '{}'.format(text, self.__class__.__name__))
 def test_get_docstring_with_ast(self):
     '''Uses the ast module to get a doctsring from a snippet of code.'''
     docstring.crop_to_docstring(self.docstring)