Skip to content

Commit a99729e

Browse files
committed
Moved 'Making Good PRs' section up in the hierarchy and clarified its content
1 parent 436f07c commit a99729e

File tree

1 file changed

+88
-54
lines changed

1 file changed

+88
-54
lines changed

getting-started/pull-request-lifecycle.rst

Lines changed: 88 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,94 @@ that you create a branch in Git, make your changes, push those changes
1616
to your fork on GitHub (``origin``), and then create a pull request against
1717
the official CPython repository (``upstream``).
1818

19+
.. _good-prs:
20+
21+
Making Good PRs
22+
===============
23+
24+
When creating a pull request, following best practices ensures your contribution is **clear, maintainable, and easy to review**. A well-structured PR improves collaboration and speeds up the review process.
25+
26+
1. **Use a Clear and Structured PR Title**
27+
28+
PR titles often become commit messages, making them **critical for maintainability and searchability**. Follow these guidelines:
29+
30+
**Do:**
31+
32+
- Clearly summarize the change in a concise manner.
33+
- Use the **imperative mood** (e.g., "Fix crash in parser" instead of "Fixed a crash in parser").
34+
- Be specific about what is being changed (avoid vague words like "Update" or "Fix").
35+
36+
**Avoid:**
37+
38+
- "Bug fix" → Too vague. What bug was fixed?
39+
- "Update README" → What was updated? Be precise.
40+
- "Refactoring" → Explain what was refactored and why.
41+
42+
**Example of a good PR title:**
43+
44+
``Improve error handling in JSON parser to prevent crashes``
45+
46+
2. **Write a Meaningful PR Description**
47+
48+
Your PR description should provide **clear context** for reviewers. Answer the following questions:
49+
50+
- **What does this PR do?**
51+
- **Why is this change necessary?**
52+
- **Are there any breaking changes?**
53+
- **Does this PR fix any open issues?** (Reference issue numbers if applicable)
54+
55+
Providing detailed descriptions makes the review process **faster and more efficient**.
56+
57+
3. **Make Your Change Against the Right Branch**
58+
59+
Ensure your PR is based on the correct branch:
60+
61+
- **New changes should target the** ``main`` **branch unless they are specific to an older version.**
62+
- If a change affects older versions, it will be **backported** after merging.
63+
- Only use **maintenance branches** when the change does not apply to ``main`` or requires a different approach.
64+
65+
Refer to :ref:`branch-merge` for more details on how backporting works.
66+
67+
4. **Follow Python's Style Guidelines**
68+
69+
- Python code should follow :PEP:`8`, and C code should follow :PEP:`7`.
70+
- Maintainers may **fix minor style issues**, but major deviations can **delay or block merging**.
71+
- PRs with **only style changes** are usually rejected unless they fix a formatting error.
72+
73+
.. note::
74+
Fixes for typos and grammar errors in documentation and docstrings are always welcome.
75+
76+
5. **Consider Backward Compatibility**
77+
78+
- Changes should **not break existing code** unless absolutely necessary.
79+
- When introducing **new arguments**, provide **default values** to maintain existing behavior.
80+
- If unsure, refer to :PEP:`387` or discuss the issue with experienced maintainers in :ref:`communication`.
81+
82+
Think about how your change affects existing users before submitting your PR.
83+
84+
6. **Ensure Proper Testing**
85+
86+
- Every PR should include **appropriate test cases** to validate the changes.
87+
- PRs without tests **will not be accepted** unless they are purely documentation changes.
88+
- Tests should **cover edge cases** and expected behaviors.
89+
- For bug fixes, add a test that **fails without the fix** and **passes after applying it**.
90+
91+
7. **Make Sure All Tests Pass**
92+
93+
- The entire test suite must **run without failures** before submission.
94+
- Run ``make test`` or refer to :ref:`runtests` to check for test failures.
95+
- Do not submit PRs with failing tests unless the failure is **directly related** to your change.
96+
97+
8. **Keep Documentation Up to Date**
98+
99+
- Any change affecting functionality should include relevant **documentation updates**.
100+
- Follow :ref:`documenting` guidelines to ensure consistency in documentation.
101+
102+
Keeping documentation updated ensures clarity for future contributors and users.
103+
104+
By following these best practices, you increase the likelihood of your PR being **quickly reviewed and merged**!
105+
106+
19107

20108
.. _pullrequest-quickguide:
21109

@@ -184,60 +272,6 @@ See `the merge command's documentation <https://git-scm.com/docs/git-merge>`_
184272
for a detailed technical explanation.
185273

186274

187-
.. _good-prs:
188-
189-
Making good PRs
190-
===============
191-
192-
When creating a pull request for submission, there are several things that you
193-
should do to help ensure that your pull request is accepted.
194-
195-
#. **Make your change against the right version of Python.** In general all
196-
changes are made against the ``main`` branch first. This includes bug fixes.
197-
After the change is merged there, it will be :ref:`ported back <branch-merge>`
198-
to older :ref:`maintenance releases <branchstatus>` as well. That way we
199-
ensure all affected versions are handled. Therefore, basing a new change
200-
directly on a maintenance branch is only used in specific circumstances,
201-
for instance when that change does not apply to ``main`` or the change
202-
requires a different approach in an older Python version compared to
203-
``main``.
204-
205-
#. **Make sure to follow Python's style guidelines.** For Python code you
206-
should follow :PEP:`8`, and for C code you should follow :PEP:`7`. If you have
207-
one or two discrepancies those can be fixed by the core developer who merges
208-
your pull request. But if you have systematic deviations from the style guides
209-
your pull request will be put on hold until you fix the formatting issues.
210-
211-
.. note::
212-
Pull requests with only code formatting changes are usually rejected. On
213-
the other hand, fixes for typos and grammar errors in documents and
214-
docstrings are welcome.
215-
216-
#. **Be aware of backwards-compatibility considerations.** While the core
217-
developer who eventually handles your pull request will make the final call on
218-
whether something is acceptable, thinking about backwards-compatibility early
219-
will help prevent having your pull request rejected on these grounds. Put
220-
yourself in the shoes of someone whose code will be broken by the change(s)
221-
introduced by the pull request. It is quite likely that any change made will
222-
break someone's code, so you need to have a good reason to make a change as
223-
you will be forcing someone to update their code. (This obviously does not
224-
apply to new classes or functions; new arguments should be optional and have
225-
default values which maintain the existing behavior.) If in doubt, have a look
226-
at :PEP:`387` or :ref:`discuss <communication>` the issue with experienced
227-
developers.
228-
229-
#. **Make sure you have proper tests** to verify your pull request works as
230-
expected. Pull requests will not be accepted without the proper tests!
231-
232-
#. **Make sure all tests pass.** The entire test suite needs to
233-
:ref:`run <runtests>` **without failure** because of your changes.
234-
It is not sufficient to only run whichever test seems impacted by your
235-
changes, because there might be interferences unknown to you between your
236-
changes and some other part of the interpreter.
237-
238-
#. Proper :ref:`documentation <documenting>` additions/changes should be included.
239-
240-
241275
Copyrights
242276
==========
243277

0 commit comments

Comments
 (0)