https://github.com/yukinarit/okome
dataclass comment parser 🍚
https://github.com/yukinarit/okome
comments dataclasses parser python
Last synced: 24 days ago
JSON representation
dataclass comment parser 🍚
- Host: GitHub
- URL: https://github.com/yukinarit/okome
- Owner: yukinarit
- License: mit
- Created: 2021-10-22T14:15:12.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-12-09T15:51:11.000Z (over 3 years ago)
- Last Synced: 2025-02-06T08:28:32.635Z (3 months ago)
- Topics: comments, dataclasses, parser, python
- Language: Python
- Homepage:
- Size: 725 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# `okome` 🍚
*dataclass comment parser*
```python
@dataclasses.dataclass
class Foo:
"""
This is a comment for class `Foo`.
"""a: int
""" This is valid comment for field that can be parsed by okome """
b: str
"""
Multi line comment
also works!
"""
```It's known to be impossible to get comments declared for dataclass and its fields. Eric V. Smith, the author of `dataclasses` module said in https://bugs.python.org/issue38401
> To change this is beyond the scope of dataclasses, and would need to be a language change. I can't think of a good way to attach the string to the annotation before it
---
With `okome`, you can get comments from dataclass!
```python
c = okome.parse(Foo)
print(f"Class comment: {c.comment}")
for f in c.fields:
print(f'Field "{f.name}" comment: {f.comment}')
```
```python
$ python simple.py
Class comment: ['This is a comment for class `Foo`.']
Field "a" comment: ['This is valid comment for field that can be parsed by okome']
Field "b" comment: ['Multi line comment', 'also works!']
```