This document serves as the SINGLE SOURCE OF TRUTH for all docstrings in the Femora project.
Location: This file is located at the Root of the repository (STYLE_GUIDE.md) to be easily accessible to all contributors and agents. It governs the documentation standards for src/femora.
A common point of confusion is "Where do I document attributes vs. arguments?".
- Class Docstring: Documents WHAT the class is and its Attributes (state stored in
self). __init__Docstring: Documents HOW to create the class and its Arguments (parameters passed to__init__).
class BeamElement:
"""Represents a finite element beam in the structural model.
<BLANK LINE>
This class handles the geometric transformation and stiffness matrix
calculations for Euler-Bernoulli beams.
<BLANK LINE>
Attributes:
tag (int): The unique identifier for this element.
nodes (list[int]): The tags of the two connected nodes [i, j].
length (float): The calculated length of the beam.
section (Section): The associated cross-section object.
"""
def __init__(self, tag: int, nodes: list[int], section: Section = None):
"""Initializes the BeamElement.
<BLANK LINE>
Args:
tag: The unique integer ID for the element.
nodes: A list of exactly two integer node tags [i-node, j-node].
section: Optional. The cross-section property. If None, a default
elastic section is assigned.
<BLANK LINE>
Raises:
ValueError: If `nodes` does not contain exactly 2 integers.
"""
self.tag = tag
self.nodes = nodes
# ... logic ...Indentation is critical for automatic parsers (Mintlify/MKDocs).
- Indent: Use 4 spaces for the body of sections (Args, Returns, etc.).
- Colon: Use
Name: Descriptionsyntax inArgs. Do NOT put types in parentheses inArgsif using type hints in the signature (Redundancy Rule). - Continuation: If a description wraps to the next line, indent it by another 4 spaces (total 8 from margin).
Args:
density: The target density of the mesh. This value is used to
calculate the average element size. (Note the extra indent here)
material_type: The name of the material.Requirement: Every Public class and "complex" public method MUST have an Example section.
- Use
>>>(REPL style) for code blocks. - Shows the user exactly how to import and use it.
"""
... (Summaries) ...
Example:
>>> import femora as fm
>>> beam = fm.BeamElement(tag=1, nodes=[10, 20])
>>> print(beam.length)
5.0
"""Any Agent working on this codebase must verify:
- Class Docstring: Has
Attributessection? (NOTArgs). - Init Docstring: Has
Argssection? (NOTAttributes). - Type Hints: Are they in the signature
def foo(x: int):? (If yes, omit(int)in docstring). - Blank Lines: Is there a blank line after the summary and before section headers?
- Example: Is there a working
Exampleblock for this public component?