mirror of
https://github.com/alirezarezvani/claude-skills.git
synced 2026-09-07 08:26:02 +00:00
- Extract commun languages rules in a separate rules/universal.md containing all cross-language rules in one place - Move language-specific rules inline into each languages/*.md file, organised into consistent sections: Security / Async / Resource Management / Exception Handling / Performance / Idioms - Add Java support: languages/java.md with full section coverage - Every review now requires exactly 2 file reads: universal.md + one language file - Add "Adding a new language" guide to SKILL.md: one file to create, nothing else changes
3.3 KiB
3.3 KiB
| language | extensions | |
|---|---|---|
| python |
|
Python — Language-Specific Review Notes
Load this file alongside rules/universal.md. Universal rules are not repeated here — only Python-specific rules and idioms.
PR Analyzer — Python Risk Signals
print()statements left in production code# noqaand# type: ignorecomments — verify they are justifiedeval()/exec()with any user-controlled inputpickleused to deserialize untrusted data- Hardcoded credentials or tokens in source
Code Quality — Python Checks
- Bare
except:orexcept Exception:swallowing silently - Mutable default arguments (
def foo(items=[])) — shared across calls import *— pollutes namespace and hides dependencies- Missing type hints on public functions and methods
assertused for runtime validation — stripped by-Oflag
Security
- Flag
eval()/exec()with any user-controlled input - Flag
pickle.loads()on untrusted data — usejsonormsgpack - Flag
subprocesscalls withshell=Trueand user input - Flag
flask.render_template_string()with user data (SSTI) - Flag
SECRET_KEY/DEBUG = Truecommitted to source
Async
- Flag
asyncio.get_event_loop().run_until_complete()inside an already-running loop - Flag mixing
threadingandasynciowithout a clear bridge (run_in_executor) - Flag CPU-bound work inside an
async defwithout offloading toProcessPoolExecutor - Flag
time.sleep()inside async functions — useawait asyncio.sleep()
Resource Management
- Flag
open()not used as a context manager (with open(...) as f) - Flag
requests.Sessioncreated per-request instead of shared/reused - Flag database connections not closed or returned to a pool on all paths
- Flag large files read entirely into memory with
.read()— prefer streaming / chunked reads
Exception Handling
- Flag bare
except:— catchesBaseExceptionincludingKeyboardInterruptandSystemExit - Flag
except Exception: pass— silently swallows errors - Flag re-raising with
raise einstead ofraise— loses the original traceback - Flag
exceptclause too broad when thetryblock covers multiple operations with different failure modes — split them
Performance
- Flag
+string concatenation in loops — use"".join() - Flag repeated
re.compile()inside a loop — compile once at module level - Flag
list.append()in a loop where a list comprehension would be more efficient - Flag
inmembership tests onlistwhere the collection is large — useset - Flag loading entire large files into memory — prefer streaming or chunked reads
Idioms and Best Practices
Type Safety
- All public functions and methods should have type annotations
- Prefer
X | None(Python 3.10+) overOptional[X] - Use
TypedDictordataclassover plaindictfor structured data
Modern Python (3.10+)
- Prefer
matchstatements over longif/elifchains - Prefer
dataclassorNamedTupleover plain classes for data carriers - Prefer
pathlib.Pathoveros.pathfor file operations - Prefer f-strings over
.format()or%formatting
None Safety
- Prefer explicit
if x is Noneover falsy checks when0or""are valid values - Flag functions returning
Noneimplicitly — make it explicit or raise