بنقرة واحدة
python-production
Python production code patterns and anti-patterns. Use when writing Python code.
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
القائمة
Python production code patterns and anti-patterns. Use when writing Python code.
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
استنادا إلى تصنيف SOC المهني
Interview the user relentlessly about a plan or design until reaching shared understanding, collecting decisions without performing implementation. Use when user wants to stress-test a plan, get grilled on their design, or mentions "grill me".
Triage TI-Toolbox telemetry error clusters from TI-toolbox-stats, using the artifact-first workflow to classify BigQuery-derived failures, compare them against current TI-Toolbox releases, and only open or close GitHub issues after review.
Use the global docx-tools CLI for Microsoft Word .docx writing workflows, including building documents from JSON specs, reading .docx files back to specs, patching specs, handling comments, adding authors/figures, and parsing BibTeX.
BIDS (Brain Imaging Data Structure) conventions for organizing neuroimaging datasets. Use when creating, reading, validating, or navigating BIDS-compliant directory trees, file names, metadata sidecars, or derivatives.
Production code quality standards and review checklist. Use when writing or reviewing code.
EEGLAB toolbox reference for EEG/MEG processing in MATLAB. Use when writing or modifying EEGLAB scripts, working with the EEG struct, ICA, clean_rawdata, ICLabel, pop_* functions, STUDY designs, or BIDS-EEG import. Covers the EEG structure, preprocessing pipeline, plugin API, and function lookup.
| name | python-production |
| description | Python production code patterns and anti-patterns. Use when writing Python code. |
| user-invocable | false |
@dataclass with type annotations for structured config. Dicts hide bugs.
# BAD
config = {"host": "localhost", "port": 8080}
# GOOD
@dataclass
class ServerConfig:
host: str
port: int = 8080
@dataclass(frozen=True) for immutable configurationOptional[T] = None, not sentinel valuespathlib.Path, never string concatenation:
# BAD
path = base_dir + "/" + subdir + "/" + filename
# GOOD
path = Path(base_dir) / subdir / filename
.resolve() to get absolute paths, .exists() to check, .mkdir(parents=True, exist_ok=True) to createlogger = logging.getLogger(__name__)basicConfig() or add handlers in library code.debug for diagnostics, info for operational events, warning for recoverable issues, error for failureslogger.info("Processing %s", filename) not logger.info(f"Processing {filename}")# Files
with open(path) as f:
data = f.read()
# Database connections
with db.connect() as conn:
conn.execute(query)
# Locks
with threading.Lock():
shared_state.update(value)
# BUG
def add_item(item, items=[]):
items.append(item)
return items
# CORRECT
def add_item(item, items=None):
if items is None:
items = []
items.append(item)
return items
__all__ in __init__.py to control public exports:
__all__ = ["Analyzer", "run_analysis", "AnalysisConfig"]
__init__.py minimal — imports and __all__, no logicfrom module import *)subprocess.run() with explicit args list:
# BAD
subprocess.run(f"cmd {user_input}", shell=True)
# GOOD
result = subprocess.run(
["cmd", user_input],
capture_output=True,
text=True,
check=True,
)
check=True to raise on non-zero exit codes (or handle returncode explicitly)class AppError(Exception):
"""Base exception for this project."""
class ConfigError(AppError):
"""Invalid configuration."""
class DataLoadError(AppError):
"""Failed to load data from source."""
except: — always catch specific exceptions# BAD
try:
process(data)
except Exception:
pass
# ACCEPTABLE (when you genuinely expect and handle the case)
try:
value = cache[key]
except KeyError:
value = compute_value(key)
__init__ state and one method, it should be a functionenum.Enum for fixed sets, not string constants:
# BAD
mode = "read" # typo-prone, no IDE completion
# GOOD
class Mode(enum.Enum):
READ = "read"
WRITE = "write"
f"Hello, {name}".format() only when the template is stored separately% formatting in new code__all__)from __future__ import annotations for forward references (Python 3.9 compatibility)def load_config(path: Path) -> ServerConfig: ...
def find_items(query: str, limit: int = 10) -> list[Item]: ...
def process(data: dict[str, Any]) -> None: ...
__main__ guard in executable modules:
def main():
# entry point logic
if __name__ == "__main__":
main()