THIS IS A TEST INSTANCE. ALL YOUR CHANGES WILL BE LOST!!!!
...
- Line width should be capped at 100 rather than the default 79
- Exceptions
- Exceptions are a means of breaking out of the normal flow of control of a code block to handle errors or other exceptional conditions.
- Never use catch-all except: statements, or catch Exception or StandardError, unless you are re-raising the exception or in the outermost block in your thread (and printing an error message). Python is very tolerant in this regard and except: will really catch everything including misspelled names, sys.exit() calls, Ctrl+C interrupts, unittest failures and all kinds of other exceptions that you simply don't want to catch.
Power Features
- It's very tempting to use these "cool" features when they're not absolutely necessary. It's harder to read, understand, and debug code that's using unusual features underneath. It doesn't seem that way at first (to the original author), but when revisiting the code, it tends to be more difficult than code that is longer but is straightforward.
- Classes
- If a class inherits from no other base classes, explicitly inherit from object. This also applies to nested classes.
- Imports
- Import modules and (and not attributes).
- Use relative import when possible (while maintaining readability).
When importing several modules from the same package use ‘,’ and ‘(‘, ‘)’. e.g.:always use parenthesis, while breaking lines between each module.
- When importing several attributes from the same module, the import should be on the same line, separated by commas.
- The import section should hold 3 (4 - optional) subsection:
- standard libs
- 3d party libs
- remote aria packages (if for readability reasons, it is better to import directly from aria, and not a relative path). - This is optional.
- aria packages (while inside this section the order should be according to the relative import 'distance' - that is, the closer the actual module is, the lower it will be. In effect ... will come before ..).
in each subsection, `import X` should come before from A import B, while inside each import and from . import . the order should be according to the length of the line
for example:
Code Block language py theme FadeToGrey firstline 1 linenumbers true import time from datetime import datetime from contextlib import contextmanager import networkx from aria import ( events, logger)logger, ) from aria.workflows.core.task import BaseTask, OperationTask from ...storage import models from .. import exceptions from . import translation from . import task as engine_task
- Naming
- if the variable is private/protectednot a part of the public API, use ‘_’ as a prefix to the variables name.
- single_trailing_underscore_: used by convention to avoid conflicts with Python keyword, e.g. class_
- between class declaration and any following member should be at least exactly one empty line
- When creating a mixin class, the name should end with ‘mixin’ (not case sensitive) - this will enable ignoring missing members.
...