-
Notifications
You must be signed in to change notification settings - Fork 143
documentation: Create CONTRIBUTING.md #5597
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5597 +/- ##
=======================================
Coverage 86.15% 86.15%
=======================================
Files 393 393
Lines 56308 56308
Branches 6492 6492
=======================================
Hits 48513 48513
Misses 6262 6262
Partials 1533 1533 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Thank you for reviewing! |
|
Wait, I'm just noticing that we could dedup the README content. |
| ## Code Style | ||
|
|
||
| We aim to follow these rules for all changes in this repository: | ||
|
|
||
| - Match existing code style and architectural patterns. | ||
| - Zero Technical Debt: Fix issues immediately. Never rely on future refactoring. | ||
| - Keep it simple: No code > Obvious code > Clever code. Do not abstract prematurely. | ||
| - Locality over DRY: Prioritize code locality. Keep related logic close together even if | ||
| it results in slight duplication. Prefer lambdas/inline logic over tiny single-use | ||
| functions (<5 LoC). Minimize variable scope. | ||
| - Self-Describing Code: Minimize comments. Use descriptive variable names and constant | ||
| intermediary variables to explain where possible. | ||
| - Guard-First Logic: Handle edge cases, invalid inputs and errors at the start of | ||
| functions. Return early to keep the "happy path" at the lowest indentation level. | ||
| - Flat Structure: Keep if/else blocks small. Avoid nesting beyond two levels if possible. | ||
| - Centralize Control Flow: Branching logic belongs in parents. Leaf functions should be | ||
| pure logic. | ||
| - Fail Fast: Detect unexpected conditions immediately. Raise Exceptions rather than | ||
| corrupt state. | ||
| - [Ask for forgiveness not permission](https://docs.python.org/3/glossary.html#term-eafp): | ||
| Assume valid keys or attributes exist and catch exceptions if the assumption proves | ||
| false. Use try-except blocks: | ||
|
|
||
| ```python | ||
| # Good | ||
| try: | ||
| return mapping[key] | ||
| except KeyError: | ||
| return default_value | ||
|
|
||
| # Bad | ||
| if key in mapping: | ||
| return mapping[key] | ||
| return default_value | ||
| ``` | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's move this to the end?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually now that I think about it, maybe we first move the existing text with minimal changes to a CONTRBUTING.md file, and then add things about code style?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea! I'll turn this into a draft, move stuff, and we'll take it from there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolved: #5604
| > [!IMPORTANT] | ||
| > | ||
| > ### Experimental Pyright Features | ||
| > | ||
| > xDSL currently relies on an experimental feature of Pyright called TypeForm. | ||
| > TypeForm is [in discussion](https://discuss.python.org/t/pep-747-typeexpr-type-hint-for-a-type-expression/55984) | ||
| > and will likely land in some future version of Python. | ||
| > | ||
| > For xDSL to type check correctly using Pyright, please add this to your `pyproject.toml`: | ||
| > | ||
| > ```toml | ||
| > [tool.pyright] | ||
| > enableExperimentalFeatures = true | ||
| > ``` | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would probably duplicate this in the readme, it applies to projects that depend on xDSL also, without it Pyright doesn't typecheck the project.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noted!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made sure to duplicate this line in #5604
Clear code quality guidelines (especially valuable if code generation tooling is used).
https://lkml.org/lkml/2026/1/7/1888