|
| 1 | + |
| 2 | +--- |
| 3 | +applyTo: '**/*' |
| 4 | +--- |
| 5 | +# General coding standards |
| 6 | +- Write clear and concise commit messages. |
| 7 | +- never use NON-BREAKING HYPHEN, use regular hyphen - |
| 8 | + |
| 9 | +--- |
| 10 | +applyTo: '**/*.py' |
| 11 | +--- |
| 12 | +# Project coding standards for Python |
| 13 | +- Follow the RUFF style guide for Python. |
| 14 | +- Be careful with unused imports, they should be removed. |
| 15 | +- Follow PEP 8 guidelines. |
| 16 | +- 4 spaces per indentation level, no tabs. |
| 17 | +- Limit all lines to a maximum of 120 characters. |
| 18 | +- Always prioritize readability and clarity. |
| 19 | +- Write clear and concise comments for each function, use google style. |
| 20 | +- Ensure functions have descriptive names and include type hints. |
| 21 | +- Maintain proper indentation (use 4 spaces for each level of indentation). |
| 22 | +- Return of methods should be assigned to a variable before being returned, unless it's a simple return. No operations should be done on return. |
| 23 | +- Avoid magic numbers; use named constants instead. |
| 24 | +- Avoid deep nesting of code blocks; refactor into smaller functions if necessary. |
| 25 | +- Avoid overly complex one-liners; break them into multiple lines if necessary. |
| 26 | +- Use consistent naming conventions (e.g., snake_case for functions and variables, PascalCase for classes). |
| 27 | +- Ensure code is modular and reusable; avoid duplication. |
| 28 | +- Include error handling where appropriate. |
| 29 | +- Make sure the output has ability to be copy-pasted directly into the codebase without further modification, place the code in a code block. |
| 30 | +- do not include # -*- coding: utf-8 -*- it is no longer needed |
| 31 | +- arg-type-hints-in-docstring = false |
| 32 | +- check-return-types = false |
| 33 | +- ignore-private-args = true |
| 34 | +- ignore-underscore-args = true |
| 35 | +- each file should include header docstring with short description of the file |
| 36 | +- use code below as and example for docstrings: |
| 37 | +```python |
| 38 | + |
| 39 | +# -*- coding: utf-8 -*- |
| 40 | +"""Example Google style docstrings. |
| 41 | +
|
| 42 | +This module demonstrates documentation as specified by the `Google Python |
| 43 | +Style Guide`_. Docstrings may extend over multiple lines. Sections are created |
| 44 | +with a section header and a colon followed by a block of indented text. |
| 45 | +
|
| 46 | +Example: |
| 47 | + Examples can be given using either the ``Example`` or ``Examples`` |
| 48 | + sections. Sections support any reStructuredText formatting, including |
| 49 | + literal blocks:: |
| 50 | +
|
| 51 | + $ python example_google.py |
| 52 | +
|
| 53 | +Section breaks are created by resuming unindented text. Section breaks |
| 54 | +are also implicitly created anytime a new section starts. |
| 55 | +
|
| 56 | +Attributes: |
| 57 | + module_level_variable1 (int): Module level variables may be documented in |
| 58 | + either the ``Attributes`` section of the module docstring, or in an |
| 59 | + inline docstring immediately following the variable. |
| 60 | +
|
| 61 | + Either form is acceptable, but the two should not be mixed. Choose |
| 62 | + one convention to document module level variables and be consistent |
| 63 | + with it. |
| 64 | +
|
| 65 | +Todo: |
| 66 | + * For module TODOs |
| 67 | + * You have to also use ``sphinx.ext.todo`` extension |
| 68 | +
|
| 69 | +.. _Google Python Style Guide: |
| 70 | + http://google.github.io/styleguide/pyguide.html |
| 71 | +
|
| 72 | +""" |
| 73 | + |
| 74 | +module_level_variable1 = 12345 |
| 75 | + |
| 76 | +module_level_variable2 = 98765 |
| 77 | +"""int: Module level variable documented inline. |
| 78 | +
|
| 79 | +The docstring may span multiple lines. The type may optionally be specified |
| 80 | +on the first line, separated by a colon. |
| 81 | +""" |
| 82 | + |
| 83 | + |
| 84 | +def function_with_types_in_docstring(param1, param2): |
| 85 | + """Example function with types documented in the docstring. |
| 86 | +
|
| 87 | + `PEP 484`_ type annotations are supported. If attribute, parameter, and |
| 88 | + return types are annotated according to `PEP 484`_, they do not need to be |
| 89 | + included in the docstring: |
| 90 | +
|
| 91 | + Args: |
| 92 | + param1 (int): The first parameter. |
| 93 | + param2 (str): The second parameter. |
| 94 | +
|
| 95 | + Returns: |
| 96 | + bool: The return value. True for success, False otherwise. |
| 97 | +
|
| 98 | + .. _PEP 484: |
| 99 | + https://www.python.org/dev/peps/pep-0484/ |
| 100 | +
|
| 101 | + """ |
| 102 | + |
| 103 | + |
| 104 | +def function_with_pep484_type_annotations(param1: int, param2: str) -> bool: |
| 105 | + """Example function with PEP 484 type annotations. |
| 106 | +
|
| 107 | + Args: |
| 108 | + param1: The first parameter. |
| 109 | + param2: The second parameter. |
| 110 | +
|
| 111 | + Returns: |
| 112 | + The return value. True for success, False otherwise. |
| 113 | +
|
| 114 | + """ |
| 115 | + |
| 116 | + |
| 117 | +def module_level_function(param1, param2=None, *args, **kwargs): |
| 118 | + """This is an example of a module level function. |
| 119 | +
|
| 120 | + Function parameters should be documented in the ``Args`` section. The name |
| 121 | + of each parameter is required. The type and description of each parameter |
| 122 | + is optional, but should be included if not obvious. |
| 123 | +
|
| 124 | + If \*args or \*\*kwargs are accepted, |
| 125 | + they should be listed as ``*args`` and ``**kwargs``. |
| 126 | +
|
| 127 | + The format for a parameter is:: |
| 128 | +
|
| 129 | + name (type): description |
| 130 | + The description may span multiple lines. Following |
| 131 | + lines should be indented. The "(type)" is optional. |
| 132 | +
|
| 133 | + Multiple paragraphs are supported in parameter |
| 134 | + descriptions. |
| 135 | +
|
| 136 | + Args: |
| 137 | + param1 (int): The first parameter. |
| 138 | + param2 (:obj:`str`, optional): The second parameter. Defaults to None. |
| 139 | + Second line of description should be indented. |
| 140 | + *args: Variable length argument list. |
| 141 | + **kwargs: Arbitrary keyword arguments. |
| 142 | +
|
| 143 | + Returns: |
| 144 | + bool: True if successful, False otherwise. |
| 145 | +
|
| 146 | + The return type is optional and may be specified at the beginning of |
| 147 | + the ``Returns`` section followed by a colon. |
| 148 | +
|
| 149 | + The ``Returns`` section may span multiple lines and paragraphs. |
| 150 | + Following lines should be indented to match the first line. |
| 151 | +
|
| 152 | + The ``Returns`` section supports any reStructuredText formatting, |
| 153 | + including literal blocks:: |
| 154 | +
|
| 155 | + { |
| 156 | + 'param1': param1, |
| 157 | + 'param2': param2 |
| 158 | + } |
| 159 | +
|
| 160 | + Raises: |
| 161 | + AttributeError: The ``Raises`` section is a list of all exceptions |
| 162 | + that are relevant to the interface. |
| 163 | + ValueError: If `param2` is equal to `param1`. |
| 164 | +
|
| 165 | + """ |
| 166 | + if param1 == param2: |
| 167 | + raise ValueError('param1 may not be equal to param2') |
| 168 | + return True |
| 169 | + |
| 170 | + |
| 171 | +def example_generator(n): |
| 172 | + """Generators have a ``Yields`` section instead of a ``Returns`` section. |
| 173 | +
|
| 174 | + Args: |
| 175 | + n (int): The upper limit of the range to generate, from 0 to `n` - 1. |
| 176 | +
|
| 177 | + Yields: |
| 178 | + int: The next number in the range of 0 to `n` - 1. |
| 179 | +
|
| 180 | + Examples: |
| 181 | + Examples should be written in doctest format, and should illustrate how |
| 182 | + to use the function. |
| 183 | +
|
| 184 | + >>> print([i for i in example_generator(4)]) |
| 185 | + [0, 1, 2, 3] |
| 186 | +
|
| 187 | + """ |
| 188 | + for i in range(n): |
| 189 | + yield i |
| 190 | + |
| 191 | + |
| 192 | +class ExampleError(Exception): |
| 193 | + """Exceptions are documented in the same way as classes. |
| 194 | +
|
| 195 | + The __init__ method may be documented in either the class level |
| 196 | + docstring, or as a docstring on the __init__ method itself. |
| 197 | +
|
| 198 | + Either form is acceptable, but the two should not be mixed. Choose one |
| 199 | + convention to document the __init__ method and be consistent with it. |
| 200 | +
|
| 201 | + Note: |
| 202 | + Do not include the `self` parameter in the ``Args`` section. |
| 203 | +
|
| 204 | + Args: |
| 205 | + msg (str): Human readable string describing the exception. |
| 206 | + code (:obj:`int`, optional): Error code. |
| 207 | +
|
| 208 | + Attributes: |
| 209 | + msg (str): Human readable string describing the exception. |
| 210 | + code (int): Exception error code. |
| 211 | +
|
| 212 | + """ |
| 213 | + |
| 214 | + def __init__(self, msg, code): |
| 215 | + self.msg = msg |
| 216 | + self.code = code |
| 217 | + |
| 218 | + |
| 219 | +class ExampleClass(object): |
| 220 | + """The summary line for a class docstring should fit on one line. |
| 221 | +
|
| 222 | + If the class has public attributes, they may be documented here |
| 223 | + in an ``Attributes`` section and follow the same formatting as a |
| 224 | + function's ``Args`` section. Alternatively, attributes may be documented |
| 225 | + inline with the attribute's declaration (see __init__ method below). |
| 226 | +
|
| 227 | + Properties created with the ``@property`` decorator should be documented |
| 228 | + in the property's getter method. |
| 229 | +
|
| 230 | + Attributes: |
| 231 | + attr1 (str): Description of `attr1`. |
| 232 | + attr2 (:obj:`int`, optional): Description of `attr2`. |
| 233 | +
|
| 234 | + """ |
| 235 | + |
| 236 | + def __init__(self, param1, param2, param3): |
| 237 | + """Example of docstring on the __init__ method. |
| 238 | +
|
| 239 | + The __init__ method may be documented in either the class level |
| 240 | + docstring, or as a docstring on the __init__ method itself. |
| 241 | +
|
| 242 | + Either form is acceptable, but the two should not be mixed. Choose one |
| 243 | + convention to document the __init__ method and be consistent with it. |
| 244 | +
|
| 245 | + Note: |
| 246 | + Do not include the `self` parameter in the ``Args`` section. |
| 247 | +
|
| 248 | + Args: |
| 249 | + param1 (str): Description of `param1`. |
| 250 | + param2 (:obj:`int`, optional): Description of `param2`. Multiple |
| 251 | + lines are supported. |
| 252 | + param3 (:obj:`list` of :obj:`str`): Description of `param3`. |
| 253 | +
|
| 254 | + """ |
| 255 | + self.attr1 = param1 |
| 256 | + self.attr2 = param2 |
| 257 | + self.attr3 = param3 #: Doc comment *inline* with attribute |
| 258 | + |
| 259 | + #: list of str: Doc comment *before* attribute, with type specified |
| 260 | + self.attr4 = ['attr4'] |
| 261 | + |
| 262 | + self.attr5 = None |
| 263 | + """str: Docstring *after* attribute, with type specified.""" |
| 264 | + |
| 265 | + @property |
| 266 | + def readonly_property(self): |
| 267 | + """str: Properties should be documented in their getter method.""" |
| 268 | + return 'readonly_property' |
| 269 | + |
| 270 | + @property |
| 271 | + def readwrite_property(self): |
| 272 | + """:obj:`list` of :obj:`str`: Properties with both a getter and setter |
| 273 | + should only be documented in their getter method. |
| 274 | +
|
| 275 | + If the setter method contains notable behavior, it should be |
| 276 | + mentioned here. |
| 277 | + """ |
| 278 | + return ['readwrite_property'] |
| 279 | + |
| 280 | + @readwrite_property.setter |
| 281 | + def readwrite_property(self, value): |
| 282 | + value |
| 283 | + |
| 284 | + def example_method(self, param1, param2): |
| 285 | + """Class methods are similar to regular functions. |
| 286 | +
|
| 287 | + Note: |
| 288 | + Do not include the `self` parameter in the ``Args`` section. |
| 289 | +
|
| 290 | + Args: |
| 291 | + param1: The first parameter. |
| 292 | + param2: The second parameter. |
| 293 | +
|
| 294 | + Returns: |
| 295 | + True if successful, False otherwise. |
| 296 | +
|
| 297 | + """ |
| 298 | + return True |
| 299 | + |
| 300 | + def __special__(self): |
| 301 | + """By default special members with docstrings are not included. |
| 302 | +
|
| 303 | + Special members are any methods or attributes that start with and |
| 304 | + end with a double underscore. Any special member with a docstring |
| 305 | + will be included in the output, if |
| 306 | + ``napoleon_include_special_with_doc`` is set to True. |
| 307 | +
|
| 308 | + This behavior can be enabled by changing the following setting in |
| 309 | + Sphinx's conf.py:: |
| 310 | +
|
| 311 | + napoleon_include_special_with_doc = True |
| 312 | +
|
| 313 | + """ |
| 314 | + pass |
| 315 | + |
| 316 | + def __special_without_docstring__(self): |
| 317 | + pass |
| 318 | + |
| 319 | + def _private(self): |
| 320 | + """By default private members are not included. |
| 321 | +
|
| 322 | + Private members are any methods or attributes that start with an |
| 323 | + underscore and are *not* special. By default they are not included |
| 324 | + in the output. |
| 325 | +
|
| 326 | + This behavior can be changed such that private members *are* included |
| 327 | + by changing the following setting in Sphinx's conf.py:: |
| 328 | +
|
| 329 | + napoleon_include_private_with_doc = True |
| 330 | +
|
| 331 | + """ |
| 332 | + pass |
| 333 | + |
| 334 | + def _private_without_docstring(self): |
| 335 | + pass |
| 336 | + |
| 337 | +``` |
0 commit comments