griffe
                                
                                 griffe copied to clipboard
                                
                                    griffe copied to clipboard
                            
                            
                            
                        Improve Docstring location information
The Docstring init method currently does this:
        self.value: str = inspect.cleandoc(value.rstrip())
        self.lineno: int | None = lineno
        self.endlineno: int | None = endlineno
The net result leading whitespace is removed from each line. This is what we want, but it now means that the there is no information about how much to add to get the correct column offset.
It would be nice if the class could provide enough information to be able to associate characters in the docstring with their line/column in the original source. Accordingly, I suggest:
- 
add a col_offsetfield indicating the size of the margin that was removed
- 
(bonus feature) add a method to convert an offset into the cleaned up doc string into original line,col. Something like: def offset_to_line_col(self, offset:int) -> Tuple[int,int]: line = self.lineno + self.value.count('\n', 0, offset) col = self.col_offset + offset - self.value.rfind('\n', 0, offset) - 1 return line, col
Implementing this would either require pulling implementation of cleandoc into the module to expose the margin or comparing the cleaned up string with the original to infer the correct value.
You can only infer the column offset for the line after the first based on this information alone. To get the offset of the first line, it would have to be passed in (from the AST node).
And of course there are tabs. I wonder how many python projects actually allow tabs?