Skip to content

build: complete the CPython notices (#2602 audit) - #2777

Merged
antonsynd merged 3 commits into
devfrom
claude/notices-audit
Nov 20, 2026
Merged

antonsynd merged 3 commits into
devfrom
claude/notices-audit

Conversation

@antonsynd

@antonsynd antonsynd commented Nov 20, 2026 •

Copy link
Copy Markdown
Owner

Why

Charter R-NJ (a); owner, 2026-11-20: "file a lane for the #2602 notices audit too". THIRD-PARTY-NOTICES.txt said its list was "not yet exhaustive". This audit read every Sharpy.Stdlib module with a CPython 3.15 namesake (55 modules) against its CPython source: Lib at 3.15.2, C sources and Doc/ at v3.14.0. It also read the Core files that follow CPython. The compiler, CLI and LSP have no ported code (comments only).

How each module was judged:

  • port: the code is translated: same decomposition, variable names, constants, regexes or tables.
  • behaviour: the same semantics, written independently. Matching CPython's messages or output format, with our own code around them, counts as behaviour.
  • borderline: a call the owner may want to look at. When in doubt, the audit attributes.

Change

Each port file now carries the PSF header lines plus "Portions…" and "Changes:" comments, and has a numbered THIRD-PARTY-NOTICES.txt entry. Each entry names the derived portions and the clause-3 changes.

File(s) Upstream What follows CPython Verdict
Stdlib Colorsys/Colorsys.cs colorsys.py every function, coefficients port
Stdlib Difflib/ SequenceMatcher, Differ, DifflibFunctions difflib.py __chain_b, find_longest_match, _fancy_replace, unified/context diff, IS_LINE_JUNK port
fnmatch_module.spy + generated C# fnmatch.py translate's bracket scan port
Stdlib Fractions/Fraction.cs fractions.py limit_denominator loop and message port
Stdlib Threading/Barrier.cs threading.py Barrier's state machine (0/1/-1/-2) and reset port
Stdlib Ipaddress/ AddressFormat, IPv4Address, IPv6Address ipaddress.py __format__ step for step; the private/public network tables port (borderline)
itertools.spy + generated C# Doc/library/itertools.rst the "roughly equivalent" combinations, permutations, combinations_with_replacement (Doc code: PSF / 0BSD) port (borderline)
os_module.spy + generated C# os.py makedirs recursion; walk's push order port (borderline)
shutil_module.spy + generated C# shutil.py _destinsrc, _basename, move fallback port (borderline)
Stdlib Urllib/UrllibModule.cs urllib/parse.py uses_netloc / uses_params tables only port (borderline)
Core PyFormatSpec.cs Python/formatter_unicode.c parse_internal_render_format_spec, refusal order and messages port
Core FloorDiv.cs, FloorMod.cs Objects/floatobject.c _float_div_mod / float_rem port
Core PyFormat.cs formatter_unicode.c existing entry widened to format_complex_internal port
Core NumericText.cs Objects/unicodeobject.c _PyUnicode_TransformDecimalAndSpaceToASCII port (borderline)
Core UnicodeCodec.cs encodings/aliases.py alias-table rows port (borderline)

The other 44 namesake modules, Str.cs and ThreadRegistry.cs are behaviour-only. Examples: .NET wrappers, a parser of our own, textbook algorithms. Datetime/DatetimeIso.cs and Fraction.Format.cs already had notices.

Spy-sourced modules: build_tools/regenerate_spy_stdlib.sh now copies a .spy file's leading # comment block into the generated C# as // lines. The shipped C# therefore keeps the notice. Regenerated files change only by those comment lines.

The notices intro drops "This list is not yet exhaustive" and its list of open files.

Packaging: every port is in Sharpy.Core or Sharpy.Stdlib. Both packages ship THIRD-PARTY-NOTICES.txt and declare Python-2.0. SharpyLang.Compiler only references Core as a project, so no ported source goes into its package.

Guard

build_tools/tests/test_third_party_notices.py:

  • STDLIB_CENSUS: an exact map from each of the 55 namesake module directories to port or behaviour.
  • test_stdlib_census_is_complete_and_honoured:
    • the map's keys equal the namesake modules on disk (by sys.stdlib_module_names);
    • a port module has a headed file that the notices list;
    • a behaviour module has no headed file.
  • test_every_listed_file_has_an_entry: the notices' file list and its numbered entries agree.
  • Six synthetic red/green unit tests and a positive control.

Mutation record

Each mutation was restored from a cp copy afterwards → 45 passed.

Mutation Result
Add a fake Pickle/Pickle.cs module 1 red: census, "no STDLIB_CENSUS row"
Flip Colorsys port → behaviour, keeping its header 1 red: census
Delete Colorsys's "Licensed under" line 3 red
Delete Colorsys's numbered entry 1 red: entries
Delete Colorsys from the file list 4 red
Regenerate with the script's notice copy disabled 2 red

Gate

Local @ caea032f1 (lane worker, measured):

  • build: 0 warnings, 0 errors;
  • build_tools/tests: 2,224 passed, 3 failed. Two are the review-line history tests, which fail the same way at origin/dev in a shallow clone (control run). One serialized-lock test was flaky under peer load and passed on rerun;
  • stdlib generate --check and spy staleness: up to date;
  • DoorCensusTests 8/8; Compiler Conformance|Infrastructure 18,518/0/0; whitespace clean.

Merged with origin/dev @ 11b0e95aa (merge tree 7caa9871a, clean): test_package_licenses.py and test_third_party_notices.py 53 passed. #2773's guard on the retired id stays green, since no new file names it.

CI gate: 85,538 passed, 0 failed, 10 skipped @ e18faf213 (measured, .NET 10 run 44804483138); Python Build Tools 44804483154, review-line 44804549038 and subjects passed. A review-line run cancelled by its successor (44804483153) is not a failure.

For the owner, not changed here

  • The per-module projects in src/Sharpy.Stdlib/modules/ are packable by default. They don't pack the notices and declare Apache-2.0 OR MIT. release.yml doesn't pack them today.
  • The Playground bundle includes Core.

Issues

Refs #2602. It closes after merge, on evidence (/close-issues).

sharpy-issues:
  closes: [2602]
  files: []

Independent review

Independent review @ 3860626: merge; 2 applied, 0 declined (reasons below); fixes 3860626..e18faf2 read by the lead

First review @ caea032f1: merge after fixes. A fresh reviewer read the behaviour modules against CPython 3.15.2 Lib and the v3.14.0 C sources and Doc. It found no missed port, and judged every attribution reasonable, the borderline ones included. The header licence text is byte-identical to CPython's LICENSE. On a merge with dev, the licence and notices guards pass 53/53.

Applied in 3860626d0:

  1. The census was per module, so a ported file could lose its notice while a sibling kept one. The reviewer stripped SequenceMatcher.cs's header, list line and entry name, and the guard stayed green (45 passed). Each port row now names its exact headed files. That mutation is now red on the census alone, and so is an extra header on a behaviour file.
  2. Nits: UnicodeCodec.cs's header now names all ten codecs, and PyFormatSpec.cs's summary says 3.14.
  3. The intro no longer reads as complete for other sources: the audit covered CPython only.

Sent to the owner, not changed here: docstring first lines copied from CPython into behaviour modules; the per-module Stdlib packages that ship no notices; Unicode CaseFolding.txt and PyYAML entries; and a crash found in passing, Fraction(-1, 3).limit_denominator(2) throwing DivideByZeroException (CPython: -1/2; #2606's control row is wrong).

Second review @ 3860626d0: merge. The reviewer ran both mutations red. It tried a set naming a missing file, a different case or separator, a subdirectory, a .spy/C# header mismatch, and row-shape refusals: all red, or caught by the staleness gate. Full build_tools/tests on a merge with dev: 2,242 passed, 1 skipped, 0 failed. Applied in e18faf213:

  1. The census comment said more than the census enforces. It now says the headed files must equal the row, an unheaded file is not seen, and the row is the record that review reads.
  2. A malformed row raised IndexError/ValueError. It is now a named problem, with a test of four shapes, mutation-tested: 4 red, then 54 green.

Generated by Claude Code

Charter row R-NJ (a): read every Sharpy.Stdlib module with a CPython 3.15
namesake (55 modules) against its CPython source, plus the Core files that
follow CPython's implementation, and notice every port.

Ports (PSF header + THIRD-PARTY-NOTICES.txt entry):
- Stdlib: Colorsys.cs; Difflib SequenceMatcher.cs, Differ.cs,
  DifflibFunctions.cs; Fraction.cs (limit_denominator); Threading
  Barrier.cs; Ipaddress AddressFormat.cs, IPv4Address.cs, IPv6Address.cs
  (borderline: __format__ and the _private_networks tables); Urllib
  UrllibModule.cs (borderline: uses_netloc/uses_params); spy-sourced
  fnmatch_module.spy, itertools.spy (borderline: the docs' equivalents),
  os_module.spy and shutil_module.spy (borderline), with their generated C#.
- Core: PyFormatSpec.cs (parse_internal_render_format_spec), FloorDiv.cs and
  FloorMod.cs (_float_div_mod / float_rem), NumericText.cs (borderline:
  _PyUnicode_TransformDecimalAndSpaceToASCII), UnicodeCodec.cs (borderline:
  encodings.aliases rows); PyFormat.cs's entry now also names RenderComplex
  (format_complex_internal's set-up).
The other 44 namesake modules are behaviour-only; Str.cs and
ThreadRegistry.cs stay behaviour-only.

regenerate_spy_stdlib.sh carries a .spy file's leading # comment block into
the generated C# as // lines, so the shipped C# keeps the notice; the
generated files change only by those comment lines.

The notices intro drops the "not yet exhaustive" sentence and its list of
open files. test_third_party_notices.py gains STDLIB_CENSUS (module ->
port | behaviour for every namesake module on disk) and a check that every
listed file has a numbered entry.

Mutation record (each red, then restored from a cp copy, then 45 passed):
- fake src/Sharpy.Stdlib/Pickle/Pickle.cs: 1 failed
  (test_stdlib_census_is_complete_and_honoured: no STDLIB_CENSUS row)
- Colorsys verdict port -> behaviour, header kept: 1 failed (census: verdict
  'behaviour' but the file carries the header)
- delete the "Licensed under" line of Colorsys.cs: 3 failed
  (claim scan, notices_and_headers_agree, census)
- delete the numbered Colorsys entry: 1 failed
  (test_every_listed_file_has_an_entry)
- delete the Colorsys line of the file list: 4 failed
- regenerate with the notice carry disabled: 2 failed
  (notices_and_headers_agree, census); restored script, regenerated, green

Refs #2602

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LGMKZYKjCq2pTmNWtKf2hy
Review fixes for PR #2777.

STDLIB_CENSUS rows now carry the exact set of headed files a port
module holds (paths under src/Sharpy.Stdlib): "Difflib": port(
"Difflib/SequenceMatcher.cs", "Difflib/Differ.cs",
"Difflib/DifflibFunctions.cs"). census_problems asserts the module's
headed set equals the recorded set, so a lost header and an extra one
are both red. It also refuses a port row with no files, a behaviour row
with files, and a row naming a file outside its module, and it requires
each port file to be listed in THIRD-PARTY-NOTICES.txt. New synthetic
tests cover a lost header in a multi-file port, an extra header in a
port module, and the three row-shape refusals.

Mutation records (restored from cp copies, never git):
- M4 (the reviewer's): strip SequenceMatcher.cs's whole leading comment
  block (the "port of" line too, so the claim scan stays silent), its
  file-list line and its name in entry 10. Red:
  test_stdlib_census_is_complete_and_honoured, with "Difflib/
  SequenceMatcher.cs: in Difflib's port set but carries no PSF header"
  and "in a 'port' module but not listed" (1 failed, 49 passed).
  Restored -> 50 passed.
- Extra header: put the PSF header lines on Difflib/__Init__.cs (a
  behaviour file in a port module), add it to the file list and to
  entry 10. Red: test_stdlib_census_is_complete_and_honoured, with
  "Difflib/__Init__.cs: carries the PSF header but is not in Difflib's
  port set" (1 failed, 49 passed). Restored -> 50 passed.

Nits: UnicodeCodec.cs's header now names all ten codecs its alias table
maps to (utf_8_sig and the _le/_be variants), matching entry 8.
PyFormatSpec.cs's summary now says CPython 3.14, as its header does.

The notices intro is scoped to the CPython audit. It no longer claims
every third-party component is listed. Code or data from other
upstreams is outside the audit, and no entry is added for it here.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LGMKZYKjCq2pTmNWtKf2hy
Second-review fix for PR #2777.

The census comment claimed a file added to a port module is read like a
new module, "header and row, or neither". It is not enforced. The census
sees only headed files, so a new unheaded file in a port module stays
green, and so does a row edited together with its header. The comment
now says what is enforced: a port module's headed files equal its row's
set, an unheaded file is not seen, and the row is the audit's record
that review reads.

census_problems also checks a row's shape before unpacking it. A bare
"port", port(""), a 1-tuple or a list set now gets a named problem ("is
not (verdict, set of file paths)") instead of a ValueError or
IndexError, covered by test_census_names_a_malformed_row.

Mutation: replaced the shape check's condition with "True or ..." so it
never fires. Red: the 4 test_census_names_a_malformed_row cases (4
failed, 50 passed). Restored from a cp copy: 54 passed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LGMKZYKjCq2pTmNWtKf2hy
@antonsynd
antonsynd merged commit 8adf932 into dev Nov 20, 2026
37 of 38 checks passed
@antonsynd
antonsynd deleted the claude/notices-audit branch November 20, 2026 20:04
antonsynd pushed a commit that referenced this pull request Nov 20, 2026
The #2777 review found one-line API summaries copied word for word from
CPython 3.15 Lib docstrings, mostly in files the #2602 census marks
"behaviour". They are documentation, not code, so the files keep no PSF
header; THIRD-PARTY-NOTICES.txt gains one section in the CPython part,
"API documentation summaries adapted from CPython docstrings", naming
the 17 files (40 summaries: 33 in behaviour files, 7 in the fnmatch and
shutil ports), the Lib modules they come from, and the PSF licence text
that follows by reference.

Method (the reviewer's): a summary matches when its first paragraph (a
C# <summary>: its whole text or first sentence), whitespace collapsed,
case and a final full stop ignored, equals the first paragraph of a
module, class or function docstring longer than 30 characters in
CPython 3.15.2's Lib (test packages, idlelib, site-packages not read);
C# generated from a .spy file is skipped. No later sentence of a
matched summary appears in a CPython docstring.

Guard: test_third_party_notices.py runs that matcher over Sharpy.Core
and Sharpy.Stdlib against python3.15's Lib (the pytest interpreter when
it is 3.15, else python3.15 on PATH, else skip with a reason) and
requires the section's list to equal the matched set. Unit tests pin the
index rule and both refusal directions without the oracle.

Mutations:
(a) drop src/Sharpy.Stdlib/spy/heapq.spy from the section: red (1
    failed, 60 passed: "heapq.spy: holds CPython docstring text ... but
    is not under 'Sharpy files holding these summaries:'");
(b) bisect_module.spy's module docstring replaced by bisect.insort's
    "Insert item x in list a, and keep it sorted assuming a is sorted.":
    red (1 failed, 60 passed: "bisect_module.spy: holds CPython
    docstring text ... <- Lib/bisect.py");
each restored with cp + cmp: green (61 passed).

Refs #2602

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LGMKZYKjCq2pTmNWtKf2hy
antonsynd pushed a commit that referenced this pull request Nov 20, 2026
The #2777 review found two derived pieces from non-CPython sources:

- src/Sharpy.Core/StringExtensions.Format.cs: the case-folding table
  (s_caseFoldTable) and the Cherokee ranges in CaseFoldChar, from the
  Unicode Character Database's CaseFolding.txt. The source records no
  version; all 125 entries equal CPython 3.15.2's str.casefold, which
  uses Unicode 17.0.0.
- src/Sharpy.Stdlib/Yaml/YamlScalarResolver.cs: Yaml11Int and
  Yaml11Float, transcribed from PyYAML 6.0.3's implicit resolvers
  (lib/yaml/resolver.py; checked against the 6.0.3 tag's file).

THIRD-PARTY-NOTICES.txt gains a section for each (upstream, version,
derived portion, full licence text), placed before the CPython section
so the CPython licence stays the file's last 277 lines. Each file gains
a short header naming its upstream and pointing at the notices. The
intro now says the #2602 audit covered CPython, names these two sources
as also listed, and claims no other completeness.

Licence texts, fetched 2026-11-20:
- PyYAML: https://raw.githubusercontent.com/yaml/pyyaml/6.0.3/LICENSE
  (sha256 8d3928f9...a577e8a4), verbatim.
- Unicode License V3: https://www.unicode.org/license.txt was refused
  by the network proxy (403); the text is the first section of
  https://raw.githubusercontent.com/unicode-org/icu/main/LICENSE (the
  Unicode Consortium's repository), verbatim, and differs from SPDX's
  Unicode-3.0 text (spdx/license-list-data) only in the copyright years
  (1991-2026 against 1991-2023).

No PackageLicenseExpression changes (the owner's call).

Refs #2602

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LGMKZYKjCq2pTmNWtKf2hy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants