Skip to content
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

gh-102213: Optimize the performance of __getattr__ #103761

Merged
merged 8 commits into from
May 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
configure* @erlend-aasland @corona10

# asyncio
**/*asyncio* @1st1 @asvetlov @gvanrossum @kumaraditya303
**/*asyncio* @1st1 @asvetlov @gvanrossum @kumaraditya303 @willingc

# Core
**/*context* @1st1
Expand All @@ -25,6 +25,8 @@ Objects/frameobject.c @markshannon
Objects/call.c @markshannon
Python/ceval.c @markshannon
Python/compile.c @markshannon @iritkatriel
Python/assemble.c @markshannon @iritkatriel
Python/flowgraph.c @markshannon @iritkatriel
Python/ast_opt.c @isidentical
Lib/test/test_patma.py @brandtbucher
Lib/test/test_peepholer.py @brandtbucher
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,10 @@ jobs:
run: echo "::add-matcher::.github/problem-matchers/gcc.json"
- name: Install Dependencies
run: sudo ./.github/workflows/posix-deps-apt.sh
- name: Set up GCC-10 for ASAN
uses: egor-tensin/setup-gcc@v1
with:
version: 10
- name: Configure OpenSSL env vars
run: |
echo "MULTISSL_DIR=${GITHUB_WORKSPACE}/multissl" >> $GITHUB_ENV
Expand Down
22 changes: 22 additions & 0 deletions .github/workflows/doc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,13 @@ jobs:

# Add pull request annotations for Sphinx nitpicks (missing references)
- name: 'Get list of changed files'
if: github.event_name == 'pull_request'
id: changed_files
uses: Ana06/get-changed-files@v2.2.0
with:
filter: "Doc/**"
- name: 'Build changed files in nit-picky mode'
if: github.event_name == 'pull_request'
continue-on-error: true
run: |
# Mark files the pull request modified
Expand All @@ -77,6 +79,26 @@ jobs:
# Build docs with the '-n' (nit-picky) option, convert warnings to errors (-W)
make -C Doc/ PYTHON=../python SPHINXOPTS="-q -n -W --keep-going" html 2>&1

# This build doesn't use problem matchers or check annotations
# It also does not run 'make check', as sphinx-lint is not installed into the
# environment.
build_doc_oldest_supported_sphinx:
name: 'Docs (Oldest Sphinx)'
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
- uses: actions/checkout@v3
- name: 'Set up Python'
uses: actions/setup-python@v4
with:
python-version: '3.11' # known to work with Sphinx 3.2
cache: 'pip'
cache-dependency-path: 'Doc/requirements-oldest-sphinx.txt'
- name: 'Install build dependencies'
run: make -C Doc/ venv REQUIREMENTS="requirements-oldest-sphinx.txt"
- name: 'Build HTML documentation'
run: make -C Doc/ SPHINXOPTS="-q" SPHINXERRORHANDLING="-W --keep-going" html

# Run "doctest" on HEAD as new syntax doesn't exist in the latest stable release
doctest:
name: 'Doctest'
Expand Down
27 changes: 27 additions & 0 deletions .github/workflows/documentation-links.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Read the Docs PR preview
# Automatically edits a pull request's descriptions with a link
# to the documentation's preview on Read the Docs.

on:
pull_request_target:
types:
- opened
paths:
- 'Doc/**'
- '.github/workflows/doc.yml'

permissions:
pull-requests: write

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
documentation-links:
runs-on: ubuntu-latest
steps:
- uses: readthedocs/actions/preview@v1
with:
project-slug: "cpython-previews"
single-version: "true"
3 changes: 3 additions & 0 deletions .mailmap
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# This file sets the canonical name for contributors to the repository.
# Documentation: https://git-scm.com/docs/gitmailmap
Amethyst Reese <amethyst@n7.gg> <john@noswap.com>
18 changes: 18 additions & 0 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Read the Docs configuration file
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
# Project page: https://readthedocs.org/projects/cpython-previews/

version: 2

sphinx:
configuration: Doc/conf.py

build:
os: ubuntu-22.04
tools:
python: "3"

commands:
- make -C Doc venv html
- mkdir _readthedocs
- mv Doc/build/html _readthedocs/html
5 changes: 3 additions & 2 deletions Doc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ JOBS = auto
PAPER =
SOURCES =
DISTVERSION = $(shell $(PYTHON) tools/extensions/patchlevel.py)
REQUIREMENTS = requirements.txt
SPHINXERRORHANDLING = -W

# Internal variables.
Expand Down Expand Up @@ -154,8 +155,8 @@ venv:
echo "To recreate it, remove it first with \`make clean-venv'."; \
else \
$(PYTHON) -m venv $(VENVDIR); \
$(VENVDIR)/bin/python3 -m pip install -U pip setuptools; \
$(VENVDIR)/bin/python3 -m pip install -r requirements.txt; \
$(VENVDIR)/bin/python3 -m pip install --upgrade pip; \
$(VENVDIR)/bin/python3 -m pip install -r $(REQUIREMENTS); \
echo "The venv has been created in the $(VENVDIR) directory"; \
fi

Expand Down
2 changes: 2 additions & 0 deletions Doc/c-api/import.rst
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ Importing Modules
.. versionchanged:: 3.3
Uses :func:`imp.source_from_cache()` in calculating the source path if
only the bytecode path is provided.
.. versionchanged:: 3.12
No longer uses the removed ``imp`` module.
.. c:function:: long PyImport_GetMagicNumber()
Expand Down
2 changes: 1 addition & 1 deletion Doc/c-api/typeobj.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1145,7 +1145,7 @@ and :c:type:`PyType_Type` effectively act as defaults.)

.. data:: Py_TPFLAGS_MANAGED_DICT

This bit indicates that instances of the class have a ``__dict___``
This bit indicates that instances of the class have a ``__dict__``
attribute, and that the space for the dictionary is managed by the VM.

If this flag is set, :const:`Py_TPFLAGS_HAVE_GC` should also be set.
Expand Down
18 changes: 9 additions & 9 deletions Doc/c-api/unicode.rst
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,15 @@ APIs:
arguments.


.. c:function:: PyObject* PyUnicode_FromObject(PyObject *obj)

Copy an instance of a Unicode subtype to a new true Unicode object if
necessary. If *obj* is already a true Unicode object (not a subtype),
return the reference with incremented refcount.

Objects other than Unicode or its subtypes will cause a :exc:`TypeError`.


.. c:function:: PyObject* PyUnicode_FromEncodedObject(PyObject *obj, \
const char *encoding, const char *errors)

Expand Down Expand Up @@ -616,15 +625,6 @@ APIs:
.. versionadded:: 3.3


.. c:function:: PyObject* PyUnicode_FromObject(PyObject *obj)

Copy an instance of a Unicode subtype to a new true Unicode object if
necessary. If *obj* is already a true Unicode object (not a subtype),
return the reference with incremented refcount.

Objects other than Unicode or its subtypes will cause a :exc:`TypeError`.


Locale Encoding
"""""""""""""""

Expand Down
11 changes: 6 additions & 5 deletions Doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,13 @@
# Short title used e.g. for <title> HTML tags.
html_short_title = '%s Documentation' % release

# Deployment preview information, from Netlify
# (See netlify.toml and https://docs.netlify.com/configure-builds/environment-variables/#git-metadata)
# Deployment preview information
# (See .readthedocs.yml and https://docs.readthedocs.io/en/stable/reference/environment-variables.html)
repository_url = os.getenv("READTHEDOCS_GIT_CLONE_URL")
html_context = {
"is_deployment_preview": os.getenv("IS_DEPLOYMENT_PREVIEW"),
"repository_url": os.getenv("REPOSITORY_URL"),
"pr_id": os.getenv("REVIEW_ID")
"is_deployment_preview": os.getenv("READTHEDOCS_VERSION_TYPE") == "external",
"repository_url": repository_url.removesuffix(".git") if repository_url else None,
"pr_id": os.getenv("READTHEDOCS_VERSION")
}

# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
Expand Down
29 changes: 29 additions & 0 deletions Doc/constraints.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# We have upper bounds on our transitive dependencies here
# To avoid new releases unexpectedly breaking our build.
# This file can be updated on an ad-hoc basis,
# though it will probably have to be updated
# whenever Doc/requirements.txt is updated.

# Direct dependencies of Sphinx
babel<3
colorama<0.5
imagesize<1.5
Jinja2<3.2
packaging<24
# Pygments==2.15.0 breaks CI
Pygments<2.16,!=2.15.0
requests<3
snowballstemmer<3
sphinxcontrib-applehelp<1.1
sphinxcontrib-devhelp<1.1
sphinxcontrib-htmlhelp<2.1
sphinxcontrib-jsmath<1.1
sphinxcontrib-qthelp<1.1
sphinxcontrib-serializinghtml<1.2

# Direct dependencies of Jinja2 (Jinja is a dependency of Sphinx, see above)
MarkupSafe<2.2

# Direct dependencies of sphinx-lint
polib<1.3
regex<2024
2 changes: 1 addition & 1 deletion Doc/library/__main__.rst
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ This is where using the ``if __name__ == '__main__'`` code block comes in
handy. Code within this block won't run unless the module is executed in the
top-level environment.

Putting as few statements as possible in the block below ``if __name___ ==
Putting as few statements as possible in the block below ``if __name__ ==
'__main__'`` can improve code clarity and correctness. Most often, a function
named ``main`` encapsulates the program's primary behavior::

Expand Down
22 changes: 11 additions & 11 deletions Doc/library/asyncio-eventloop.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1438,9 +1438,7 @@ async/await code consider using the high-level

* *stdin* can be any of these:

* a file-like object representing a pipe to be connected to the
subprocess's standard input stream using
:meth:`~loop.connect_write_pipe`
* a file-like object
* the :const:`subprocess.PIPE` constant (default) which will create a new
pipe and connect it,
* the value ``None`` which will make the subprocess inherit the file
Expand All @@ -1450,9 +1448,7 @@ async/await code consider using the high-level

* *stdout* can be any of these:

* a file-like object representing a pipe to be connected to the
subprocess's standard output stream using
:meth:`~loop.connect_write_pipe`
* a file-like object
* the :const:`subprocess.PIPE` constant (default) which will create a new
pipe and connect it,
* the value ``None`` which will make the subprocess inherit the file
Expand All @@ -1462,9 +1458,7 @@ async/await code consider using the high-level

* *stderr* can be any of these:

* a file-like object representing a pipe to be connected to the
subprocess's standard error stream using
:meth:`~loop.connect_write_pipe`
* a file-like object
* the :const:`subprocess.PIPE` constant (default) which will create a new
pipe and connect it,
* the value ``None`` which will make the subprocess inherit the file
Expand All @@ -1483,6 +1477,11 @@ async/await code consider using the high-level
as text. :func:`bytes.decode` can be used to convert the bytes returned
from the stream to text.

If a file-like object passed as *stdin*, *stdout* or *stderr* represents a
pipe, then the other side of this pipe should be registered with
:meth:`~loop.connect_write_pipe` or :meth:`~loop.connect_read_pipe` for use
with the event loop.

See the constructor of the :class:`subprocess.Popen` class
for documentation on other arguments.

Expand Down Expand Up @@ -1571,7 +1570,7 @@ Server objects are created by :meth:`loop.create_server`,
:meth:`loop.create_unix_server`, :func:`start_server`,
and :func:`start_unix_server` functions.

Do not instantiate the class directly.
Do not instantiate the :class:`Server` class directly.

.. class:: Server

Expand Down Expand Up @@ -1662,7 +1661,8 @@ Do not instantiate the class directly.

.. attribute:: sockets

List of :class:`socket.socket` objects the server is listening on.
List of socket-like objects, ``asyncio.trsock.TransportSocket``, which
the server is listening on.

.. versionchanged:: 3.7
Prior to Python 3.7 ``Server.sockets`` used to return an
Expand Down
9 changes: 7 additions & 2 deletions Doc/library/asyncio-subprocess.rst
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,9 @@ their completion.
Interact with process:

1. send data to *stdin* (if *input* is not ``None``);
2. read data from *stdout* and *stderr*, until EOF is reached;
3. wait for process to terminate.
2. closes *stdin*;
3. read data from *stdout* and *stderr*, until EOF is reached;
4. wait for process to terminate.

The optional *input* argument is the data (:class:`bytes` object)
that will be sent to the child process.
Expand All @@ -229,6 +230,10 @@ their completion.
Note, that the data read is buffered in memory, so do not use
this method if the data size is large or unlimited.

.. versionchanged:: 3.12

*stdin* gets closed when `input=None` too.

.. method:: send_signal(signal)

Sends the signal *signal* to the child process.
Expand Down
52 changes: 52 additions & 0 deletions Doc/library/calendar.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,58 @@ interpreted as prescribed by the ISO 8601 standard. Year 0 is 1 BC, year -1 is
2 BC, and so on.


.. class:: Day

Enumeration defining the days of the week as integer constants, from 0 to 6.

.. attribute:: MONDAY

.. attribute:: TUESDAY

.. attribute:: WEDNESDAY

.. attribute:: THURSDAY

.. attribute:: FRIDAY

.. attribute:: SATURDAY

.. attribute:: SUNDAY

.. versionadded:: 3.12


.. class:: Month

Enumeration defining months of the year as integer constants, from 1 to 12.

.. attribute:: JANUARY

.. attribute:: FEBRUARY

.. attribute:: MARCH

.. attribute:: APRIL

.. attribute:: MAY

.. attribute:: JUNE

.. attribute:: JULY

.. attribute:: AUGUST

.. attribute:: SEPTEMBER

.. attribute:: OCTOBER

.. attribute:: NOVEMBER

.. attribute:: DECEMBER

.. versionadded:: 3.12


.. class:: Calendar(firstweekday=0)

Creates a :class:`Calendar` object. *firstweekday* is an integer specifying the
Expand Down
Loading