-
Notifications
You must be signed in to change notification settings - Fork 1
/
napoleon.py
171 lines (131 loc) · 4.12 KB
/
napoleon.py
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
"""
Boring docstring for the module itself
"""
import logging
from collections import namedtuple
from typing import NamedTuple, TypedDict, TypeVar, Union
import nott.so.serious
from ..sub import Irrelevant, Nonsense, Unused as ReallyUnused
from serious import *
from other.module import Product
from some.module import Imported
if True:
from some.module import ConditionallyImported
logger = logging.getLogger(__name__)
SOME_CONST = 1
T = TypeVar('V') # (deliberate name mismatch)
SomeTuple = namedtuple("_SomeTuple", ["val"])
SomeTypedTuple = NamedTuple("_SomeTypedTuple", (("val", str),))
SomeTypedDict = TypedDict("_SomeTypedDict", val=str)
NewClass = type("_NewClass", (object,), {})
class TopLevel(object):
@staticmethod
def static(cls, self):
return cls, self
@some_decorator(with_args)
@classmethod
def clsmethod(cls, self):
"""
Args:
self (Any)
Returns:
Any
"""
return self
def method(obj, cls):
return cls
if SOME_CONST:
def conditionally_defined_method(obj, cls):
return cls
def first(products, getter):
"""
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
commodo consequat.
Args:
products (Union[Iterable[Dict], Iterable[engine.models.Product]])
getter (Callable[[str], Callable])
Returns:
Dict[int, List[ConditionallyImported]]: {<product id>: <product videos>}
"""
from some.module import InnerImported
print "Python 2 print statement"
print("parenthesised print statement")
return {}
def second(products, getter):
"""
Duis aute irure dolor in reprehenderit in voluptate
velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat
cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id
est laborum.
Args:
products (Iterable[engine.models.Product]): blah blah
getter (Callable[[str], Callable]): something else
Returns:
Dict[int, List[TopLevel]]
NOTE:
whatever
"""
class InnerClass(object):
raise ValueError, "WTF python 2"
def second_inner(product, key, default):
"""
Args:
product (Dict[str, Any])
key (MysteryType[str]): this type has not been imported and is not
defined in the document!
default (Imported)
Raises:
ExceptionError
"""
pass
try:
third([], 1)
except ValueError, e:
# disgusting Python 2.5 exception format
pass
return {}
def third(product_ids, user_id=None):
"""
Donec massa sapien faucibus et molestie ac feugiat sed. Eget mi proin sed
libero. Nulla aliquet enim tortor at auctor urna nunc. Massa placerat duis
ultricies lacus sed turpis. Eleifend mi in nulla posuere sollicitudin
aliquam ultrices.
Kwargs:
product_ids (List[int])
user_id (Optional[int]): if given, also set the "liked" flag, meaning
the current user has liked a product in the list
"""
pass
def fourth(product_id, user_id):
# type: (int, int) -> str
"""
Already annotated
"""
return 'whatever'
def fifth(product_ids, user_id=None):
"""
Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus
saepe eveniet ut et voluptates repudiandae sint et molestiae non
recusandae.
Kwargs:
product_ids: this arg has no type info
user_id (Optional[int]): if given, also set the "liked" flag, meaning
the current user has liked a product in the list
Returns:
bool
"""
pass
def sixth(product_ids):
"""
Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus
saepe eveniet ut et voluptates repudiandae sint et molestiae non
recusandae.
Args:
product_ids (Iterable[int])
Yields:
int
"""
for id_ in product_ids:
yield id_