aboutsummaryrefslogtreecommitdiffstats
path: root/tests/query/highlights/python/docstrings.py
blob: 02c0a2cc6d17f66bdb261e0d8002d57c055e820c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# Docstrings according to PEP 257 (https://peps.python.org/pep-0257/)
# <- @comment

"""Module docstring assigned to `__doc__`..."""
# <- @string.documentation
"""
... with an addtional docstring, not part of `__doc__`.
"""
# <- @string.documentation

"""
Some random docstring in the middle if nowhere...
"""
# <- @string.documentation
"""
... also with not one ...
"""
# <- @string.documentation
"""
... but two addtional docstrings.
"""
# <- @string.documentation

oneline_string_assignment = "not detected as docstring"
#                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @string
#                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^ !@string.documentation
"""Module attribute docstring."""
# <- @string.documentation

multiline_string_assignment = """
                              also not detected as docstring
                              """
#                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @string
#                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ !@string.documentation

looks_like_implicit_string_concatenation = "abc"
#                                          ^^^^^ @string 
"def"
# <- @string.documentation

single_line_implicit_string_concatenation = "abc" "def"
#                                           ^^^^^ @string 
#                                                 ^^^^^ @string 
#                                                 ^^^^^ !@string.documentation 

multiline_implicit_string_concatenation = (
    "not "
    # <- @string
    # <- !@string.documentation
    "detected "
    # <- @string
    # <- !@string.documentation
    "as docstring, "
    # <- @string
    # <- !@string.documentation
    "either."
    # <- @string
    # <- !@string.documentation
)


class A:
    """
    Class docstring, assigned to `__doc__`.
    """
    # <- @string.documentation

    """
    Some random docstring again, ...
    """
    # <- @string.documentation
    """
    ... with an "additional" docstring. Again.
    """
    # <- @string.documentation

    foo = "class attribute"
    #     ^^^^^^^^^^^^^^^^^ @string
    #     ^^^^^^^^^^^^^^^^^ !@string.documentation
    """
    Class attribute docstring, but an attribute 
    does not have a `__doc__` attribute itself.
    """
    # <- @string.documentation

    bar: int
    """Class attribute docstring, type annotation only."""
    # <- @string.documentation

    baz: str = "type annotated class attribute"
    #          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @string
    #          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ !@string.documentation
    """Class attribute docstring, type annotation and assignment."""
    # <- @string.documentation

    def __init__(self):
        """Method docstring."""
        # <- @string.documentation

        self.quux = "instance attribute"
        #           ^^^^^^^^^^^^^^^^^^^^ @string
        #           ^^^^^^^^^^^^^^^^^^^^ !@string.documentation
        """Instance attribute docstring."""
        # <- @string.documentation


def f(x):
    """Function docstring."""
    # <- @string.documentation
    """Addtional function docstring."""
    # <- @string.documentation
    return x**2


f.a = 1
"""Function attribute docstring."""
# <- @string.documentation


"Random docstring with single quotes - legal, but far off standard and confusing."
# <- @string.documentation