mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 10:44:36 +08:00
* Render CPython defaults in generated text signatures Arguments whose default rendered as `<unrepresentable>`, while the same callable has a representable default in CPython, now render that default: - Where the Rust value can be a literal, the argument becomes a plain field with `default = <literal>`. - The remaining cases keep their Rust default and add `py_default` with a comment. These are wrappers such as ArgIntoFloat or ArgIntoBool, values that need the VM, enums, and Option where None means another value. Byte string literals render as Python bytes. A function registered under several names gets an internal doc per name, so its __doc__ no longer carries the signature header. Removed expectedFailure from test_pydoc tests that now pass. Assisted-by: Grok:grok-4.7 Assisted-by: Claude:claude-opus-5-5 * Match native callable signatures to CPython names and kinds Rename parameters and adjust positional-only / keyword-only kinds and defaults of native functions and methods so their generated text signatures match CPython. Remove expectedFailure markers from tests that now pass. Assisted-by: Claude:claude-opus-5-5 Assisted-by: Grok:grok-4.7 * Fix Windows console read size and keep type.__prepare__ permissive Assisted-by: Claude:claude-opus-5-5 * Derive signature defaults from typed Rust values Param.default is now a DefaultRepr rendered by the const writer. Literals, integer and bool constants become typed defaults, and other default expressions use the type's const fn py_default. A bare `optional` renders as None, so `default = None` rewrites are reverted. Address review comments: zlib max_length defaults, get_ca_certs binary_form keyword, getpeercert der, WASM ssl certificate keywords, fstatvfs fd-only, and _sre endpos shown as sys.maxsize. Assisted-by: Claude:claude-opus-5-5 Assisted-by: Grok:grok-4.7 * Generate class constructor text signatures at compile time A #[pyclass] impl composes the type's internal doc from the Args of its Initializer or Constructor, so type.__text_signature__ and inspect.signature work for native classes. __doc__ stays the plain doc. Struct sequences get (iterable=(), /) and __reduce__ (self, /). Hand-parsed constructors are converted to FromArgs structs, and _weakref.proxy is split from ProxyType. Assisted-by: Claude:claude-opus-5-5 Assisted-by: Grok:grok-4.7 * Remove expectedFailure from test_hmac tests that now pass Assisted-by: Claude:claude-opus-5-5 * Match remaining native signatures and count missing CPython signatures as matches Give lock.__enter__ and RLock.__enter__ their own no-argument methods, add FromArgs for start_new_thread and start_joinable_thread keeping their errors, take RTLD_GLOBAL/RTLD_LOCAL from libc, and align names, kinds and <unrepresentable> defaults where CPython's signature is invalid (bytes.hex, reduce, warn, link, setlocale, add_done_callback, ...). getaddrinfo accepts keyword arguments. whats_left treats a callable CPython has no signature for as matching. Assisted-by: Claude:claude-opus-5-5 Assisted-by: Grok:grok-4.7 * Drop unfulfilled dead_code expectation on os.link dir_fd args Assisted-by: Claude:claude-opus-5-5 * Distinguish OptionalArg and Option in signature defaults An `optional` field's signature default now comes from its type: Option<T> renders None, while OptionalArg<T> (a missing argument that is not any Python value) renders <unrepresentable>. Fields where a missing argument behaves exactly like None become Option<T>; fields whose missing state differs keep OptionalArg. Redundant py_default = "<unrepresentable>" entries are removed. Assisted-by: Claude:claude-opus-5-5 Assisted-by: Grok:grok-4.7 * Remove expectedFailure from test_rlcompleter.test_attr_matches Assisted-by: Claude:claude-opus-5-5 * Use Option for optional arguments whose missing and None states match OptionalOption and OptionalArg<Option<T>> fields that treat a missing argument like None become Option<T> with #[pyarg(optional)], which renders =None in the text signature. Plain optional parameters of that kind move into small FromArgs structs. Uses where missing and None differ (reduce initial, StringIO newline, TextIOWrapper.reconfigure, set_asyncgen_hooks) keep OptionalOption. Assisted-by: Claude:claude-opus-5-5 Assisted-by: Grok:grok-4.7 * Render ::NAME defaults by name and restore named constant defaults - default = ::NAME writes NAME into the text signature and stores Into::into(NAME) as the Rust value. - A one-field tuple-struct argument pattern such as Fildes(fd) names the parameter after its binding, so fcntl and termios keep destructuring. - zlib, lzma, syslog, mmap and select defaults use their named constants again instead of literals or <unrepresentable>. Assisted-by: Claude:claude-opus-5-5 Assisted-by: Grok:grok-4.7 * Name FromArgs fields after their Python parameters Drop #[pyarg(name = ...)] where the Python name is a valid Rust field name and rename the field instead. The option stays only for keywords (fn, loop, final, type, self) and the non-snake_case memLevel. Assisted-by: Claude:claude-opus-5-5 Assisted-by: Grok:grok-4.7 * Build literal defaults from Python values and type <unrepresentable> - default = LIT on a non-primitive field converts the literal through ToPyObject and TryFromObject when the argument is missing, so object fields no longer need a vm expression plus a matching py_default. - A bare default on a primitive integer, bool or float field renders its zero value. - DefaultRepr::Unrepresentable replaces the <unrepresentable> text, and py_default = "<unrepresentable>" is a compile error. - pyexpat.ParserCreate distinguishes a missing intern from intern=None, mmap AccessMode renders its value, and sqlite blobopen names rowid. Assisted-by: Claude:claude-opus-5-5 Assisted-by: Grok:grok-4.7 * Resolve native docstrings from the doc database at compile time - rustpython-doc stores its table as a sorted const slice with const fn lookups (get, get_attr, class_attr_doc) instead of a phf map, and the update-doc-db workflow emits that form. - Class, method, getset, module function and struct sequence docs, and per-class slot wrapper docs, are chosen by const lookups in the derive output. The database text wins over Rust doc comments. - Macros reach the table through rustpython_vm::__exports, so only the vm depends on rustpython-doc. - Remove expectedFailure markers from doctest and pydoc tests that pass. Assisted-by: Claude:claude-opus-5-5 Assisted-by: Grok:grok-4.7 * Keep time.gmtime, localtime and ctime without a text signature Their [seconds] parameter has no text signature, and unittest.mock relies on inspect.signature failing for them. Take OptionalOption again so the default stays unrepresentable, and treat None like a missing argument. Assisted-by: Claude:claude-opus-5-5
127 lines
4.0 KiB
YAML
127 lines
4.0 KiB
YAML
name: Update doc DB
|
|
|
|
permissions: {}
|
|
|
|
on:
|
|
workflow_dispatch:
|
|
inputs:
|
|
python-version:
|
|
description: Target python version to generate doc db for
|
|
type: string
|
|
default: "3.14.7"
|
|
base-ref:
|
|
description: Base branch to create the update branch from
|
|
type: string
|
|
default: "main"
|
|
|
|
defaults:
|
|
run:
|
|
shell: bash
|
|
|
|
jobs:
|
|
generate:
|
|
permissions:
|
|
contents: read
|
|
runs-on: ${{ matrix.os }}
|
|
strategy:
|
|
matrix:
|
|
os:
|
|
- ubuntu-latest
|
|
- windows-latest
|
|
- macos-latest
|
|
steps:
|
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
with:
|
|
persist-credentials: false
|
|
sparse-checkout: |
|
|
crates/doc
|
|
|
|
- uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
|
|
with:
|
|
python-version: ${{ inputs.python-version }}
|
|
|
|
- name: Generate docs
|
|
run: python crates/doc/generate.py
|
|
|
|
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
|
with:
|
|
name: doc-db-${{ inputs.python-version }}-${{ matrix.os }}
|
|
path: "crates/doc/generated/*.json"
|
|
if-no-files-found: error
|
|
retention-days: 7
|
|
overwrite: true
|
|
|
|
merge:
|
|
runs-on: ubuntu-latest
|
|
needs: generate
|
|
permissions:
|
|
contents: write
|
|
pull-requests: write
|
|
steps:
|
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
with:
|
|
persist-credentials: true
|
|
ref: ${{ inputs.base-ref }}
|
|
|
|
- name: Create update branch
|
|
run: git switch -c "update-doc-${PYTHON_VERSION}"
|
|
env:
|
|
PYTHON_VERSION: ${{ inputs.python-version }}
|
|
|
|
- name: Download generated doc DBs
|
|
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
|
|
with:
|
|
pattern: "doc-db-${{ inputs.python-version }}-**"
|
|
path: crates/doc/generated/
|
|
merge-multiple: true
|
|
|
|
- name: Transform JSON
|
|
env:
|
|
PYTHON_VERSION: ${{ inputs.python-version }}
|
|
run: |
|
|
# Merge all artifacts
|
|
jq -s "add" --sort-keys crates/doc/generated/*.json > crates/doc/generated/merged.json
|
|
|
|
# Format merged json as a sorted const slice
|
|
jq -r 'to_entries[] | " (\(.key | @json), \(.value | @json)),"' crates/doc/generated/merged.json > crates/doc/generated/raw_entries.txt
|
|
|
|
OUTPUT_FILE='crates/doc/src/data.inc.rs'
|
|
|
|
# shellcheck disable=SC2016
|
|
{
|
|
echo '// This file was auto-generated by `.github/workflows/update-doc-db.yml`.'
|
|
echo "// CPython version: ${PYTHON_VERSION}"
|
|
echo '// spell-checker: disable'
|
|
echo ''
|
|
echo '#[rustfmt::skip]'
|
|
echo 'pub const DB: &[(&str, &str)] = &['
|
|
cat crates/doc/generated/raw_entries.txt
|
|
echo '];'
|
|
} > "$OUTPUT_FILE"
|
|
|
|
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
|
with:
|
|
name: doc-db-${{ inputs.python-version }}
|
|
path: "crates/doc/src/data.inc.rs"
|
|
if-no-files-found: error
|
|
retention-days: 7
|
|
overwrite: true
|
|
|
|
- name: Commit, push and create PR
|
|
env:
|
|
GH_TOKEN: ${{ github.token }}
|
|
PYTHON_VERSION: ${{ inputs.python-version }}
|
|
BASE_REF: ${{ inputs.base-ref }}
|
|
run: |
|
|
git config user.name "github-actions[bot]"
|
|
git config user.email "github-actions[bot]@users.noreply.github.com"
|
|
if [ -n "$(git status --porcelain)" ]; then
|
|
git add crates/doc/src/data.inc.rs
|
|
git commit -m "Update doc DB for CPython ${PYTHON_VERSION}"
|
|
git push -u origin HEAD
|
|
gh pr create \
|
|
--base "${BASE_REF}" \
|
|
--title "Update doc DB for CPython ${PYTHON_VERSION}" \
|
|
--body "Auto-generated by update-doc-db workflow."
|
|
fi
|