It is advised to use PEP 8 Style Guide.
- Python uses snake case variables by default.
- Line length should be at most 79. Use \ to break up a line.
one, two, three, four, five, size, seven, eight, nine, \ ten, eleven = token.split()
- Some files should be broken down into more files because they are too long (e.g. flask/app/utils.py).
- Use list instead of dictionary when the index is an integer. It's a more pythonic approach.
OR
browsers = [] for i in range(N): browsers.append(Browser())
OR better yetbrowsers = [None] * N for i in range(N): browsers[i] = Browser()
browsers = [Browser() for i in range(N)]
- Use dictionaries as switches instead of if-else.
mapping = { 'main': 'Main Item', 'testrun': 'Testrun', 'testcase_sequence': 'Test Case Sequence', 'teststep_sequence': 'test_step' } if item_type in mapping: return mapping[item_type] return ''
- Use enums for constants.
from enum import Enum class Color(Enum): RED = 1 GREEN = 2 BLUE = 3
- Use data classes.
AddressCreate.py
seems like a good candidate. Could also be a good alternative to having dynamic**kwargs
argument.
- Complete type hinting in function arguments and return.
from typing import List, Optional
def func(a: int, b: string, c: Optional[int] = None) -> List[int]:
ret = [a, b]
if c:
ret.append(c)
return ret
- Use with syntax to automatically file even on exception. This is already being used, but some parts still use f.close()
with open(...) as f: pass
- Parsing and converting code is bit hacky with many .replace() calls. Maybe try a formal approach with a parser, then work on the syntax tree.
- Use Marshmallow to serialize SQL schemas into JSON.
- Database calls should be abstracted away from the controllers in views.py.
- Use Flask Blueprints to make a subroute for each
item_type
.