Hướng dẫn -1 index in python

This document is for an old version of Python that is no longer supported. You should upgrade and read the Python documentation for the current stable release.

© Copyright 1990-2020, Python Software Foundation.
The Python Software Foundation is a non-profit corporation. Please donate.
Last updated on Jun 19, 2020. Found a bug?
Created using Sphinx 2.3.1.

Edit this page

Toggle table of contents sidebar

This guide is a comprehensive resource for contributing to Python – for both new and experienced contributors. It is maintained by the same community that maintains Python. We welcome your contributions to Python!

Quick Reference#

Here are the basic steps needed to get set up and contribute a patch. This is meant as a checklist, once you know the basics. For complete instructions please see the setup guide.

  1. Install and set up Git and other dependencies (see the Git Setup page for detailed information).

  2. Fork the CPython repository to your GitHub account and get the source code using:

    git clone https://github.com/<your_username>/cpython
    cd cpython
    

  3. Build Python, on UNIX and Mac OS use:

    ./configure --with-pydebug && make -j
    

    and on Windows use:

    See also more detailed instructions, how to install and build dependencies, and the platform-specific pages for UNIX, Mac OS, and Windows.

  4. Run the tests:

    On most Mac OS X systems, replace ./python with ./python.exe. On Windows, use python.bat.

  5. Create a new branch where your work for the issue will go, e.g.:

    git checkout -b fix-issue-12345 main
    

    If an issue does not already exist, please create it. Trivial issues (e.g. typo fixes) do not require any issue to be created.

  6. Once you fixed the issue, run the tests, run make patchcheck, and if everything is ok, commit.

  7. Push the branch on your fork on GitHub and create a pull request. Include the issue number using gh-NNNN in the pull request description. For example:

    gh-12345: Fix some bug in spam module
    

  8. Add a News entry into the Misc/NEWS.d directory as individual file. The news entry can be created by using blurb-it, or the blurb tool and its blurb add command. Please read more about blurb in documentation.

Note

First time contributors will need to sign the Contributor Licensing Agreement (CLA) as described in the Licensing section of this guide.

Here are some links that you probably will reference frequently while contributing to Python:

  • Issue tracker

  • Buildbot status

  • Where to Get Help

  • PEPs (Python Enhancement Proposals)

  • Git Bootcamp and Cheat Sheet

Status of Python branches#

Moved to Status of Python Versions

Contributing#

We encourage everyone to contribute to Python and that’s why we have put up this developer’s guide. If you still have questions after reviewing the material in this guide, then the Core Python Mentorship group is available to help guide new contributors through the process.

A number of individuals from the Python community have contributed to a series of excellent guides at Open Source Guides.

Core developers and contributors alike will find the following guides useful:

  • How to Contribute to Open Source

  • Building Welcoming Communities

Guide for contributing to Python:

We recommend that the documents in this guide be read as needed. You can stop where you feel comfortable and begin contributing immediately without reading and understanding these documents all at once. If you do choose to skip around within the documentation, be aware that it is written assuming preceding documentation has been read so you may find it necessary to backtrack to fill in missing concepts and terminology.

Proposing changes to Python itself#

Improving Python’s code, documentation and tests are ongoing tasks that are never going to be “finished”, as Python operates as part of an ever-evolving system of technology. An even more challenging ongoing task than these necessary maintenance activities is finding ways to make Python, in the form of the standard library and the language definition, an even better tool in a developer’s toolkit.

While these kinds of change are much rarer than those described above, they do happen and that process is also described as part of this guide:

  • Adding to the Stdlib

  • Changing the Python Language

Other Interpreter Implementations#

This guide is specifically for contributing to the Python reference interpreter, also known as CPython (while most of the standard library is written in Python, the interpreter core is written in C and integrates most easily with the C and C++ ecosystems).

There are other Python implementations, each with a different focus. Like CPython, they always have more things they would like to do than they have developers to work on them. Some major examples that may be of interest are:

  • PyPy: A Python interpreter focused on high speed (JIT-compiled) operation on major platforms

  • Jython: A Python interpreter focused on good integration with the Java Virtual Machine (JVM) environment

  • IronPython: A Python interpreter focused on good integration with the Common Language Runtime (CLR) provided by .NET and Mono

  • Stackless: A Python interpreter focused on providing lightweight microthreads while remaining largely compatible with CPython specific extension modules

Key Resources#

  • Coding style guides
    • PEP 7 (Style Guide for C Code)

    • PEP 8 (Style Guide for Python Code)

  • Issue tracker
    • Meta tracker (issue tracker for the issue tracker)

    • Experts Index

  • Buildbot status

  • Source code
    • Browse online

    • Snapshot of the *main* branch

    • Daily OS X installer

  • PEPs (Python Enhancement Proposals)

  • Where to Get Help

  • Developer Log

Additional Resources#

  • Anyone can clone the sources for this guide. See Helping with the Developer’s Guide.

  • Help with …
    • Exploring the Internals

    • Changing CPython’s Grammar

    • Guide to the Parser

    • Compiler Design

    • Garbage Collector Design

  • Tool support
    • GDB Support

    • Dynamic Analysis with Clang

    • Various tools with configuration files as found in the Misc directory

    • Information about editors and their configurations can be found in the wiki

  • python.org maintenance

  • Search this guide

Code of Conduct#

Please note that all interactions on Python Software Foundation-supported infrastructure is covered by the PSF Code of Conduct, which includes all infrastructure used in the development of Python itself (e.g. mailing lists, issue trackers, GitHub, etc.). In general this means everyone is expected to be open, considerate, and respectful of others no matter what their position is within the project.

Full Table of Contents#

  • Getting Started
    • Setup and Building
      • Install git
      • Get the source code
      • Compile and build
      • Install dependencies
      • Regenerate configure
      • Regenerate the ABI dump
      • Troubleshoot the build
      • Editors and Tools
      • Directory structure
    • Fixing “easy” Issues (and Beyond)
    • Git Bootcamp and Cheat Sheet
      • Forking CPython GitHub Repository
      • Cloning a Forked CPython Repository
      • Listing the Remote Repositories
      • Setting Up Your Name and Email Address
      • Enabling autocrlf on Windows
      • Creating and Switching Branches
      • Deleting Branches
      • Renaming Branch
      • Staging and Committing Files
      • Reverting Changes
      • Stashing Changes
      • Comparing Changes
      • Pushing Changes
      • Creating a Pull Request
      • Updating your CPython Fork
      • Applying a Patch to Git
      • Downloading Other’s Patches
      • Accepting and Merging a Pull Request
      • Backporting Merged Changes
      • Editing a Pull Request Prior to Merging
      • GitHub CLI
    • Lifecycle of a Pull Request
      • Introduction
      • Quick Guide
      • Step-by-step Guide
      • Making Good PRs
      • patchcheck
      • Making Good Commits
      • Licensing
      • Submitting
      • Converting an Existing Patch from b.p.o to GitHub
      • Reviewing
      • Leaving a Pull Request Review on GitHub
      • Dismissing Review from Another Core Developer
      • Committing/Rejecting
      • Crediting
    • Where to Get Help
      • Discourse
      • Mailing Lists
      • Ask #python-dev
      • Zulip
      • Core Mentorship
      • Core Developers Office Hours
      • File a Bug
  • Development Workflow
    • Following Python’s Development
      • Standards of behaviour in these communication channels
      • Mailing Lists
      • Discourse (discuss.python.org web forum)
      • Discord (private chat server)
      • IRC
      • Blogs
      • Setting Expectations for Open Source Participation
      • Additional Repositories
    • Development Cycle
      • Branches
      • Stages
      • Repository Administration
    • Adding to the Stdlib
      • Adding to a pre-existing module
      • Adding a new module
    • Standard Library Extension Modules
    • Changing Python’s C API
      • The internal API
      • Public C API
      • Limited API
    • Changing the Python Language
      • What Qualifies
      • PEP Process
      • Suggesting new features and language changes
    • Changing CPython’s Grammar
      • Abstract
      • Checklist
    • Porting to a New Platform
  • Issues and Triaging
    • Issue Tracker
      • Using the Issue Tracker
      • Disagreement With a Resolution on the Issue Tracker
    • Triaging an Issue
      • Checklist for Triaging
      • Helping Triage Issues
    • GitHub Labels
      • General purpose labels
      • Labels specific to issues
      • Labels specific to PRs
      • GitHub Labels for PRs
      • Applying labels for Issues
      • Generating Special Links in a Comment
    • GitHub Issues for BPO Users
      • How to format my comments nicely?
      • How to attach files to an issue?
      • How to link to file paths in the repository when writing comments?
      • How to do advanced searches?
      • Where is the “nosy list”?
      • How to add issue dependencies?
      • What on Earth is a “mannequin”?
      • Where did the “Resolution” field go?
      • Where did the “Low”, “High”, and “Critical” priorities go?
      • How to find a random issue?
      • Where are regression labels?
    • Triage Team
      • Becoming a member of the Python triage team
  • Documentation
    • Getting Started
      • Introduction
      • Building the documentation
      • Style Guide
      • Translating
    • Helping with Documentation
      • Python Documentation
      • Helping with documentation issues
      • Proofreading
    • Style Guide
      • Use of whitespace
      • Footnotes
      • Capitalization
      • Affirmative Tone
      • Economy of Expression
      • Security Considerations (and Other Concerns)
      • Code Examples
      • Code Equivalents
      • Audience
    • reStructuredText Markup
      • Quick Reference
      • reStructuredText Primer
      • Additional Markup Constructs
    • Translating
      • Starting a new translation
      • PEP 545 summary
      • How to get help
      • Translation FAQ
    • Helping with the Developer’s Guide
      • Developer’s Guide workflow
  • Testing and Buildbots
    • Running and Writing Tests
      • Running
      • Writing
      • Benchmarks
    • Silence Warnings From the Test Suite
    • Increase Test Coverage
      • Common Gotchas
      • Measuring Coverage
      • Filing the Issue
      • Measuring coverage of C code with gcov and lcov
    • Working with Buildbots
      • In case of trouble
      • Buildbot failures on Pull Requests
      • Checking results of automatic builds
      • Stability
      • Flags-dependent failures
      • Ordering-dependent failures
      • Transient failures
      • Custom builders
    • New Buildbot Workers
      • Preparing for buildbot worker setup
      • Setting up the buildbot worker
      • Buildbot worker operation
      • Required Ports
      • Required Resources
      • Security Considerations
  • Core Developers
    • Responsibilities
      • Mailing Lists and Bug Notifications
      • Sign a Contributor Agreement
      • Pull Request merging
      • Expectations
    • Accepting Pull Requests
      • Assessing a pull request
      • Updating NEWS and What’s New in Python
      • Working with Git
    • Experts Index
      • Stdlib
      • Tools
      • Platforms
      • Miscellaneous
      • Documentation Translations
    • Developer Log
      • Procedure for Granting or Dropping Access
    • Motivations and Affiliations
      • Published entries
      • Goals of this page
      • Limitations on scope
    • How to Become a Core Developer
      • What it Takes
      • Gaining Commit Privileges
  • CPython’s Internals
    • Exploring the Internals
      • CPython Source Code Layout
      • Additional References
    • Guide to the Parser
      • Abstract
      • How PEG Parsers Work
      • Syntax
      • Pegen
      • Testing
      • Debugging generated parsers
      • References
    • Compiler Design
      • Abstract
      • Parsing
      • Abstract Syntax Trees (AST)
      • Memory Management
      • Source Code to AST
      • Control Flow Graphs
      • AST to CFG to Bytecode
      • Introducing New Bytecode
      • Code Objects
      • Important Files
      • Known Compiler-related Experiments
      • References
    • Garbage Collector Design
      • Abstract
      • Memory layout and object structure
      • Identifying reference cycles
      • Destroying unreachable objects
      • Optimization: generations
      • Optimization: reusing fields to save memory
      • Optimization: delay tracking containers
  • Advanced Tools
    • GDB Support
      • gdb 7 and later
      • gdb 6 and earlier
      • Updating auto-load-safe-path to allow test_gdb to run
    • Dynamic Analysis with Clang
      • What is Clang?
      • What are Sanitizers?
      • Clang/LLVM Setup
      • Python Build Setup
    • Coverity Scan
      • Access to analysis reports
      • Building and uploading analysis
      • Known limitations
      • Modeling
      • Workflow
      • Contact
  • Status of Python Versions
    • Supported Versions
    • Unsupported versions
    • Status key