Skip to content

Commit

Permalink
Add support for Python raw docstrings
Browse files Browse the repository at this point in the history
Sometimes, in Python, a docstring will be a raw (`r"..."`) string, as
opposed to a regular (`"..."`) string (I've seen this when a docstring
needs to escape things in funny ways for sphinx). This commit adds two
entries to the `Python.quote` section of `languages.json` (and the
corresponding update to `constants.go`) for recognizing these raw
docstrings as docs rather than code.

For example, without this commit, for the file

```python
r"""Welcome to foo.py! Sometimes I escape :class:`thing`\s funny when
Sphinx is involved.
"""

def hello():
    pass
```

`scc` reports

```
───────────────────────────────────────────────────────────────────────────────
Language                 Files     Lines   Blanks  Comments     Code Complexity
───────────────────────────────────────────────────────────────────────────────
Python                       1         6        0         0        6          0
───────────────────────────────────────────────────────────────────────────────
Total                        1         6        0         0        6          0
───────────────────────────────────────────────────────────────────────────────
Estimated Cost to Develop (organic) $125
Estimated Schedule Effort (organic) 0.45 months
Estimated People Required (organic) 0.02
───────────────────────────────────────────────────────────────────────────────
Processed 117 bytes, 0.000 megabytes (SI)
───────────────────────────────────────────────────────────────────────────────
```

But with this commit, reports

```
───────────────────────────────────────────────────────────────────────────────
Language                 Files     Lines   Blanks  Comments     Code Complexity
───────────────────────────────────────────────────────────────────────────────
Python                       1         6        1         3        2          0
───────────────────────────────────────────────────────────────────────────────
Total                        1         6        1         3        2          0
───────────────────────────────────────────────────────────────────────────────
Estimated Cost to Develop (organic) $39
Estimated Schedule Effort (organic) 0.29 months
Estimated People Required (organic) 0.01
───────────────────────────────────────────────────────────────────────────────
Processed 117 bytes, 0.000 megabytes (SI)
───────────────────────────────────────────────────────────────────────────────
```

Thanks for your consideration!
  • Loading branch information
wbadart committed Nov 22, 2022
1 parent fff7a11 commit 75cb873
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
10 changes: 10 additions & 0 deletions languages.json
Expand Up @@ -5360,6 +5360,16 @@
"docString": true,
"end": "'''",
"start": "'''"
},
{
"docString": true,
"end": "\"\"\"",
"start": "r\"\"\""
},
{
"docString": true,
"end": "'''",
"start": "r'''"
}
],
"shebangs": [
Expand Down
4 changes: 2 additions & 2 deletions processor/constants.go

Large diffs are not rendered by default.

0 comments on commit 75cb873

Please sign in to comment.