| applyTo | **/*.py,**/*.ipynb |
|---|
Applies to Jupyter notebooks and standalone .py scripts.
- Type annotations everywhere — parameters, return types, non-obvious variables
- Verify with Pylance (strict mode preferred)
- No abbreviations. Write out names.
figurenotfig.axisnotax.i,j,kfor indices OK - Prefer named functions over code block comments. Comments explain why, not what
- Split into meaningful functions — ideally pure, easy to test
- Apply basic functional programming where it improves readability (map, filter, list comprehensions)
- f-strings preferred over
%or.format()for string interpolation - No
+concatenation in loops — use"".join()or list accumulation is/is notforNonecomparisons, never==/!=- Truthiness:
if seq:notif len(seq) > 0:;if x is not None:notif x != None: - Use
pathlib.Pathoveros.pathfor file operations
X | NoneoverOptional[X];X | YoverUnion[X, Y](PEP 604)- Abstract container types in signatures:
Sequenceoverlist,Mappingoverdict
- Order: stdlib → third-party → local; one blank line between groups
- No wildcard imports (
from x import *) - One import statement per module line; multiple names from same module OK:
from x import A, B
- No bare
except:— always name specific exceptions (except ValueError:) - No mutable default arguments:
def f(x: list = [])— useNone+ guard - Use
withfor all file/resource management; never manual open/close
- No generic names — no "util", "helper", "common", "shared"
- Module-level constants:
UPPER_CASE_WITH_UNDERSCORES - DRY only for domain-related concerns
- No magic numbers — extract named constants for literal comparisons
- Public functions require
"""..."""docstring (triple double quotes) - First line imperative mood, ends with period:
"""Compute distances from center.""" - Multi-line: blank line after summary, then
Args:,Returns:,Raises:sections as needed
- Extract charts and tables into standalone
.pyscript withmain()entry point - Original notebook →
explore/with metadata"code_graph_analysis_pipeline_data_validation": "ValidateAlwaysFalse"and "Exploration" added to title - Charts → SVG, tables → CSV, descriptions → Markdown summary report