Add feature to parse Python docstrings

This commit is contained in:
2026-04-13 14:44:04 +02:00
parent 16852f3d68
commit b71b93000e
5 changed files with 58 additions and 11 deletions
+20 -1
View File
@@ -12,10 +12,19 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from enum import Enum
import docstring_parser
__all__ = [
'PythonDocstringStyle',
'PythonDocstring'
]
class PythonDocstringStyle(Enum):
SPHINX = 'sphinx'
NUMPY = 'numpy'
GOOGLE = 'google'
class PythonDocstring:
'''
Represents a Python docstring.
@@ -33,4 +42,14 @@ class PythonDocstring:
def __eq__(self, value) -> bool:
if not isinstance(value, type(self)):
return False
return self.docstring == value.docstring
return self.docstring == value.docstring
def parse(self) -> docstring_parser.Docstring:
'''
Parses the docstring.
:return: The parsed docstring.
:rtype: docstring_parser.Docstring
'''
return docstring_parser.parse(self.docstring)