From 84a8883eb0542ea0cdefc59aed627c5b2deb5338 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Fri, 20 Nov 2026 07:18:48 -0800 Subject: [PATCH 1/8] chore(quest): claim quest/m1/ffi-export/python-private-names.md Quest-Claim: e0be21bf23c65d4a From db663303a73c7eb17e2bb2f345572ecba6b5e71e Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Fri, 20 Nov 2026 07:31:12 -0800 Subject: [PATCH 2/8] fix(ffi): a Python module lists its exports in __all__ A Rust pub fn whose name starts with `_` declared a stub pyright strict reported as an unused private function. Listing every export in __all__ counts each as used, and makes `from import *` reach it. Co-Authored-By: Claude Opus 5.5 --- ffi/README.md | 4 +++- ffi/fixtures/api/src/lib.rs | 6 ++++++ ffi/src/python.rs | 13 +++++++++++++ ffi/surface/api/c.h | 3 ++- ffi/surface/api/cpp.hpp | 1 + ffi/surface/api/dart.dart | 1 + ffi/surface/api/go.txt | 1 + ffi/surface/api/kotlin.kt | 1 + ffi/surface/api/python.pyi | 1 + ffi/surface/api/swift.swift | 1 + ffi/surface/api/web.d.ts | 1 + ffi/surface/moq/python.pyi | 1 + ffi/tests/api.py | 11 +++++++++++ 13 files changed, 43 insertions(+), 2 deletions(-) diff --git a/ffi/README.md b/ffi/README.md index 3ebe7c326..e171971cb 100644 --- a/ffi/README.md +++ b/ffi/README.md @@ -835,7 +835,9 @@ caller imports it with no ignores. top-level names that clash. A keyword, a member Python gives every such class, or a method named as a field takes a trailing `_`. A member or top-level name may be a builtin's (`bytes`, `int`): the module reads each builtin through an alias (`_bytes`). - Constructors such as `new` stay static methods: `Counter.new(1)`. + Constructors such as `new` stay static methods: `Counter.new(1)`. The module's `__all__` + lists every export, so `from moq import *` reaches one whose Rust name starts with `_` + too, and none of the module's own imports or helpers. - **Objects** are classes owning their handle, freed once their last reference goes, which the caller's reference keeps through a call, so there is no `close()`. A `self` method, or passing the object by value, moves its value out, after which a call raises diff --git a/ffi/fixtures/api/src/lib.rs b/ffi/fixtures/api/src/lib.rs index 5375942c6..d44bec63f 100644 --- a/ffi/fixtures/api/src/lib.rs +++ b/ffi/fixtures/api/src/lib.rs @@ -5375,6 +5375,12 @@ pub fn deprecated(note: u8) -> u8 { note } +/// One more than `note`, by a name starting with an underscore, which `pub` still exports, +/// and which Python's module takes for its own deprecation decorator. +pub fn _deprecated(note: u8) -> u8 { + note + 1 +} + /// A dial, whose docs carry each rustdoc form a binding renders as its own: links to a /// method [`Self::turn`], a field [`Dial::level`], a variant [`Error::Overflow`], a /// function [`advance`], a constant [`LIMIT`], an object [`Counter`], a callback's method diff --git a/ffi/src/python.rs b/ffi/src/python.rs index 4c8aa2277..7ea03ac16 100644 --- a/ffi/src/python.rs +++ b/ffi/src/python.rs @@ -198,6 +198,15 @@ pub(crate) fn generate(abi: &Abi<'_>, packages: &str, contract: u64) -> Result import *` reaches, a name + // starting with `_` too. The runtime's public classes join them, as annotations name them. + let exports: BTreeSet<&str> = (g.names.keys()) + .map(String::as_str) + .filter(|name| !TAKEN.contains(name)) + .chain(["Duration", "ForeignReader", "Mut", "Waker"]) + .collect(); + let all: String = exports.iter().map(|name| format!("\t\"{name}\",\n")).collect(); let native = indent_by(NATIVE, 1); let natives: String = g.natives.iter().map(|n| format!("\n{}", indent_by(n, 2))).collect(); let head = format!( @@ -246,6 +255,7 @@ pub(crate) fn generate(abi: &Abi<'_>, packages: &str, contract: u64) -> Result Gen<'a> { if abi.ranges.values().any(|ty| matches!(ty, Type::Bound(_))) { let bound = abi.rt("bound"); self.register(&bound, "Bound".to_string()); + self.names.insert("Bound".to_string(), "the runtime's range bound".to_string()); self.py.push_str( "class Bound(_enum.Enum):\n\t\"\"\"What a range's start or end bound does: nothing, include its value, or exclude it.\"\"\"\n\n\tUNBOUNDED = 0\n\tINCLUDED = 1\n\tEXCLUDED = 2\n\n\n", ); @@ -827,6 +838,7 @@ impl<'a> Gen<'a> { for (c, n) in &abi.arrays { let name = Abi::array_class(*n); self.register(c, name.clone()); + self.names.insert(name.clone(), format!("the class of `[u8; {n}]`")); let _ = write!( self.py, "class {name}(_bytes):\n\t\"\"\"A Rust `[u8; {n}]`: exactly {n} bytes.\"\"\"\n\n\t__slots__ = ()\n\n\tdef __new__(cls, value: {BUFFER}) -> _typing.Self:\n\t\tself = _bytes.__new__(cls, value)\n\t\tif _len(self) != {n}:\n\t\t\traise _ValueError(f\"{{_len(self)}} bytes, not {n}\")\n\t\treturn self\n\n\n" @@ -1068,6 +1080,7 @@ impl<'a> Gen<'a> { other => unreachable!("{other:?} is no range"), }; self.register(c, name.clone()); + self.names.insert(name.clone(), "a range's class".to_string()); let fields: Vec = (fields.into_iter()) .map(|(name, ty)| Slot { name: name.to_string(), diff --git a/ffi/surface/api/c.h b/ffi/surface/api/c.h index a8ab6ae04..84c120459 100644 --- a/ffi/surface/api/c.h +++ b/ffi/surface/api/c.h @@ -17,7 +17,7 @@ #ifdef __cplusplus extern "C" { #endif -#define API_CONTRACT ((uint64_t)0x06b4a9cf5dcdd72bULL) +#define API_CONTRACT ((uint64_t)0x63394d403cb27cc7ULL) uint64_t api_contract(void); uint32_t api_target(void); typedef int32_t api_status; @@ -2485,6 +2485,7 @@ API_MUST_USE api_poll api_unescaped_maybe_poll(api_unescaped_maybe_future *futur void api_unescaped_maybe_future_free(api_unescaped_maybe_future *future); API_MUST_USE api_buf api_unzeroed(api_buf bytes); uint8_t api_deprecated(uint8_t note); +uint8_t api__deprecated(uint8_t note); api_Knob api_knob(api_Dial dial); typedef struct api_level_later_future api_level_later_future; API_MUST_USE api_level_later_future *api_level_later(api_Dial dial); diff --git a/ffi/surface/api/cpp.hpp b/ffi/surface/api/cpp.hpp index 354bbb087..f0182d99d 100644 --- a/ffi/surface/api/cpp.hpp +++ b/ffi/surface/api/cpp.hpp @@ -1786,6 +1786,7 @@ namespace api { inline ::api::unescaped_maybe_future unescaped_maybe(::std::optional<::api::input> text); inline ::api::buf unzeroed(::api::input bytes); inline ::std::uint8_t deprecated(::std::uint8_t note); + inline ::std::uint8_t _deprecated(::std::uint8_t note); [[deprecated]] inline ::api::Knob knob(const ::api::Dial &dial); [[deprecated("read its `level`")]] inline ::api::level_later_future level_later(const ::api::Dial &dial); inline ::api::result<::api::Dial, ::api::Error> turned(const ::api::Dial &dial, ::std::unique_ptr<::api::Turner> turner); diff --git a/ffi/surface/api/dart.dart b/ffi/surface/api/dart.dart index 37fa94869..28ece4ee1 100644 --- a/ffi/surface/api/dart.dart +++ b/ffi/surface/api/dart.dart @@ -1934,6 +1934,7 @@ Cancelable unescapedLater(String text); Cancelable unescapedMaybe(String? text); typed.Uint8List unzeroed(typed.Uint8List bytes); int deprecated(int note); +int deprecated_(int note); @Deprecated('') Knob knob(Dial dial); @Deprecated('read its `level`') Cancelable levelLater(Dial dial); Dial turned(Dial dial, Turner turner); diff --git a/ffi/surface/api/go.txt b/ffi/surface/api/go.txt index 6fa1755d6..f748fad40 100644 --- a/ffi/surface/api/go.txt +++ b/ffi/surface/api/go.txt @@ -52,6 +52,7 @@ func Crammed(a Moment, b Moment, n0 uint64, n1 uint64, n2 uint64, n3 uint64, n4 func Cross(left LeftRightU8, right RightLeftU8) uint8 func Crowded(reading Reading, a Stamp, b Stamp, n0 uint64, n1 uint64, n2 uint64, n3 uint64, n4 uint64, n5 uint64, n6 uint64, n7 uint64, n8 uint64, n9 uint64, n10 uint64, n11 uint64, n12 uint64, n13 uint64, n14 uint64, n15 uint64, n16 uint64, n17 uint64, n18 uint64, n19 uint64, n20 uint64, n21 uint64, n22 uint64, n23 uint64, n24 uint64, n25 uint64, n26 uint64, n27 uint64, n28 uint64, n29 uint64, n30 uint64, n31 uint64, n32 uint64, n33 uint64, n34 uint64, n35 uint64, n36 uint64, n37 uint64, n38 uint64, n39 uint64, n40 uint64, n41 uint64, n42 uint64, n43 uint64, n44 uint64, n45 uint64, n46 uint64, n47 uint64, n48 uint64, n49 uint64, n50 uint64, n51 uint64, n52 uint64, n53 uint64, n54 uint64, n55 uint64, n56 uint64, n57 uint64, n58 uint64, n59 uint64, n60 uint64, n61 uint64, n62 uint64, n63 uint64, n64 uint64, n65 uint64, n66 uint64, n67 uint64, n68 uint64, n69 uint64, n70 uint64, n71 uint64, n72 uint64, n73 uint64, n74 uint64, n75 uint64, n76 uint64, n77 uint64, n78 uint64, n79 uint64, n80 uint64, n81 uint64, n82 uint64, n83 uint64, n84 uint64, n85 uint64, n86 uint64, n87 uint64, n88 uint64, n89 uint64, n90 uint64, n91 uint64, n92 uint64, n93 uint64, n94 uint64, n95 uint64, n96 uint64, n97 uint64, n98 uint64, n99 uint64, n100 uint64, n101 uint64, n102 uint64, n103 uint64, n104 uint64, n105 uint64, n106 uint64, n107 uint64, n108 uint64, n109 uint64, n110 uint64, n111 uint64, n112 uint64, n113 uint64, n114 uint64, n115 uint64, n116 uint64, n117 uint64, n118 uint64) (uint64, error) func Deprecated_(note uint8) uint8 +func Deprecated__(note uint8) uint8 func Describe(event Event) (string, error) func DescribeNonZeros(nonZeros NonZeros) (string, error) func Digit(r *p_rt.Bytes) (uint8, error) diff --git a/ffi/surface/api/kotlin.kt b/ffi/surface/api/kotlin.kt index 2e51b7a18..8a033b566 100644 --- a/ffi/surface/api/kotlin.kt +++ b/ffi/surface/api/kotlin.kt @@ -1678,6 +1678,7 @@ suspend fun unescapedLater(text: kotlin.String): kotlin.String suspend fun unescapedMaybe(text: kotlin.String?): kotlin.String? fun unzeroed(bytes: api.Bytes): api.Bytes fun deprecated(note: kotlin.UByte): kotlin.UByte +fun deprecated_(note: kotlin.UByte): kotlin.UByte @kotlin.Deprecated("") fun knob(dial: api.Dial): api.Knob @kotlin.Deprecated("read its `level`") suspend fun levelLater(dial: api.Dial): kotlin.ULong @kotlin.jvm.Throws(ErrorException::class) fun turned(dial: api.Dial, turner: api.Turner): api.Dial diff --git a/ffi/surface/api/python.pyi b/ffi/surface/api/python.pyi index 5fb6c4fae..e4b938c50 100644 --- a/ffi/surface/api/python.pyi +++ b/ffi/surface/api/python.pyi @@ -1,4 +1,5 @@ # api.py +__all__ = ['A', 'Area', 'Array', 'ArrayU8x4', 'Atlas', 'B', 'BOXED', 'Batch', 'Batch2', 'Beat', 'Berth', 'Board', 'Booth', 'Bound', 'BoundU64', 'BoundsU64', 'BoundsU64Exception', 'BoxedU16', 'BoxedU8', 'Builtin', 'C', 'CancellationError', 'Cancelled', 'Channel', 'Choice', 'Clash', 'ClashAny', 'ClashBreak', 'ClashCandidate', 'ClashEmptyString', 'ClashEscaped', 'ClashSeed', 'ClashSpan', 'ClashStore', 'ClashTone', 'ClashTone_', 'Clocked', 'Codecs', 'Core', 'Countdown', 'Counter', 'Cursor', 'Deprecated', 'Der', 'Dial', 'Digest', 'DoubleArray', 'Draft', 'Duration', 'Error', 'ErrorException', 'Event', 'Extent', 'FAR', 'Family', 'Fault', 'FaultException', 'Feed', 'FiledReceipt', 'ForeignReader', 'Forged', 'GREETINGS', 'Gap', 'Gauge', 'Handle', 'Hasher', 'Hits', 'Holder', 'Hooked', 'InnerU8', 'Instant', 'Journal', 'Json', 'JvmField', 'JvmStatic', 'Key', 'Knob', 'LIMIT', 'Label', 'Labeled', 'Labelled', 'Latch', 'Layered', 'Ledger', 'LeftRightU8', 'LeftU8', 'Level', 'LimitsBytes', 'LimitsDuration', 'ListClashToneException', 'Local', 'LocalWaiter', 'Log', 'LogCount', 'LogThread', 'Logger', 'LongArray', 'MacrosStreams', 'Mark', 'Marker', 'Measure', 'Message', 'Meter', 'Meters', 'Moment', 'Mut', 'Name', 'Node', 'NonZeros', 'Note', 'Numbers', 'OptIn', 'OuterInnerU8', 'PRIMES', 'Packaged', 'Packet', 'PadU16', 'PadU8', 'Page', 'PairNonZeroU16', 'PairSizeU8', 'PairU32', 'PairU8Size', 'Parcel', 'Part', 'Pass', 'Peer', 'Pinned', 'Placement', 'Plain', 'Platform', 'Point', 'PolarPoint', 'PolarTurn', 'Polar_Turn', 'Qualifiers', 'Quantity', 'Rank', 'Rated', 'Reading', 'Receipt', 'Refusal', 'RefusalException', 'Registry', 'Resolving', 'Retired', 'Retry', 'RightLeftU8', 'RightU8', 'STEP', 'Scan', 'Score', 'Seat', 'Shadowed', 'Shape', 'Sheet', 'Site', 'Size', 'Slip', 'SlotU32', 'SlotU8', 'Span', 'Spawned', 'Spot', 'Stack', 'Stage', 'Stamp', 'Stamped', 'StartSeekable', 'Status', 'StdIoError', 'StringException', 'Tab', 'Tallies', 'Tally', 'Ticket', 'Tier', 'TlsCert', 'TlsCodec', 'TlsConfig', 'TlsPolicyLifetime', 'TlsResolver', 'TlsSession', 'Token', 'Trail', 'Turner', 'URL', 'Url', 'VecClashTone', 'Verbosity', 'Version', 'Waiter', 'Waker', 'Weighted', 'Wide', 'Window', 'Worker', 'WrapU32', '_deprecated_', 'admit', 'advance', 'after', 'alpn', 'alpn_lent', 'apply_non_zero_u16', 'apply_u32', 'area', 'assert_', 'attempt', 'beats', 'below', 'booth_count', 'boxed_counter', 'boxed_floats', 'boxed_name', 'boxed_tuple', 'breadth', 'bump_both', 'bump_either', 'byte_len', 'byte_limits', 'capacities_2_2', 'capacities_2_4', 'capacities_4_2', 'capacities_4_4', 'cert_der', 'cert_len', 'certify', 'chain_len', 'choose', 'chunks', 'clash_any', 'clash_audible', 'clash_audio_encoder_finish', 'clash_audio_encoder_finish_', 'clash_candidate', 'clash_empty', 'clash_ignore', 'clash_nested', 'clocked_after', 'coordinates', 'corner', 'corner_later', 'count', 'counted', 'counters', 'crammed', 'cross', 'crowded', 'deprecated', 'describe', 'describe_non_zeros', 'digit', 'divide', 'doubled', 'doubled_i64', 'doubled_ttl', 'drain_2', 'drain_4', 'drive', 'dropped', 'each', 'either', 'either_later', 'emit', 'emit_from_thread', 'emit_later', 'encode', 'end', 'ends', 'entries', 'erased', 'errno', 'excuse', 'extended', 'failure', 'failure_kind', 'failure_message', 'farther_hop', 'file', 'fill_2', 'fill_4', 'filter', 'find', 'fingerprint', 'first_of', 'flip', 'greet', 'grow', 'halved', 'halves', 'has_instant', 'has_text', 'heft', 'held_count', 'hex', 'hook', 'host', 'is_family', 'is_kept', 'jam', 'jni_one', 'join_words', 'joined', 'jvm_sum', 'keep_point', 'keeper_point', 'keeps', 'kept_counter', 'kept_or_point', 'kept_point', 'kept_polar_point', 'kept_size', 'kept_wrap_u32', 'knob', 'lasting', 'later', 'layer_name', 'least', 'len', 'lent_back', 'less', 'level_later', 'local_after', 'local_later', 'local_or_new', 'local_or_new_later', 'locals_dropped', 'log_counts', 'log_later', 'log_on_drop', 'log_waker', 'longer', 'longest', 'louder', 'macros_streamed', 'made', 'marked', 'moment_at', 'named', 'next_char', 'next_hop', 'next_ips', 'next_packet', 'nexts', 'non_zeros', 'now', 'nudge', 'nudge_by', 'numbered', 'offered_len', 'offset', 'offsetof', 'on_first_thread', 'only', 'page', 'pair', 'parents', 'parse_cert', 'parse_later', 'peek', 'placement', 'platform', 'pointer_bits', 'polar_point', 'poll_tripled', 'port', 'ports', 'prefixed', 'push_counted', 'put_number', 'queued_hex', 'reach', 'read_len', 'reading', 'reading_bump', 'reading_debug', 'reading_echo', 'reasons', 'refuse', 'reissue', 'reissue_lent', 'relay', 'report_non_zero_u16', 'report_u32', 'resolve', 'resolved', 'resolver', 'resume', 'return_moved', 'return_values', 'rooted_name', 'rows', 'same', 'same_char', 'same_duration', 'same_ip_addr', 'same_isize', 'same_labelled', 'same_path', 'same_socket_addr', 'same_socket_addr_v4', 'same_socket_addr_v6', 'same_string', 'same_u128', 'same_u64', 'same_usize', 'sample_hex', 'scaled', 'scanned', 'seat', 'second_later', 'sections', 'secure', 'seeds_counter_counter', 'seeds_counter_point', 'seeds_counter_polar_point', 'seeds_counter_size', 'seeds_counter_wrap_u32', 'seeds_point_counter', 'seeds_point_point', 'seeds_point_polar_point', 'seeds_point_size', 'seeds_point_wrap_u32', 'seek_to', 'sentence', 'shift', 'shifted', 'since', 'span', 'spell', 'spend', 'split_last', 'spread', 'stamp_at', 'stored', 'stored_text', 'stray', 'sum_all', 'sum_lists', 'sum_u32', 'summed', 'summed_up_receipt', 'sums', 'swapped', 'tag', 'tagged', 'tail', 'tallied', 'tally_log_count', 'tick_name', 'tickets', 'timed_hex', 'title', 'token_bytes', 'token_slice', 'total', 'turned', 'unescaped', 'unescaped_later', 'unescaped_maybe', 'unhook', 'unnamed', 'unzeroed', 'verify', 'visit_chunks', 'visit_stray', 'walk', 'wasm_log', 'wasm_only', 'wasm_take', 'watch', 'weigh_all_counter', 'weigh_point', 'wide', 'widen', 'widths', 'wind', 'within', 'words', 'worth', 'yielded'] class Waker: def __init__(self, wake: _typing.Callable[[], _object], loop: _asyncio.AbstractEventLoop | None=None) -> None: ... def wake(self) -> None: ... diff --git a/ffi/surface/api/swift.swift b/ffi/surface/api/swift.swift index 41e70dc3f..0a8d2ffe3 100644 --- a/ffi/surface/api/swift.swift +++ b/ffi/surface/api/swift.swift @@ -1760,6 +1760,7 @@ public let URL: Swift.UInt64 @inlinable nonisolated(nonsending) public func unescapedMaybe(_ text: Swift.String?) async throws -> Swift.String? @inlinable public func unzeroed(_ bytes: borrowing Swift.Span) -> Bytes @inlinable public func deprecated(_ note: Swift.UInt8) -> Swift.UInt8 +@inlinable public func deprecated_(_ note: Swift.UInt8) -> Swift.UInt8 @available(*, deprecated) @inlinable public func knob(_ dial: Dial) -> Knob @available(*, deprecated, message: "read its `level`") @inlinable nonisolated(nonsending) public func levelLater(_ dial: Dial) async throws -> Swift.UInt64 @inlinable public func turned(_ dial: Dial, _ turner: any Turner) throws -> Dial diff --git a/ffi/surface/api/web.d.ts b/ffi/surface/api/web.d.ts index fe741b111..18dfe9337 100644 --- a/ffi/surface/api/web.d.ts +++ b/ffi/surface/api/web.d.ts @@ -2746,6 +2746,7 @@ export declare function unescapedLater(text: string): rt.Call; export declare function unescapedMaybe(text: string | undefined): rt.Call; export declare function unzeroed(bytes: Uint8Array | rt.Bytes): rt.Bytes; export declare function deprecated(note: number): number; +export declare function deprecated_(note: number): number; export declare function knob(dial: Dial): Knob; export declare function levelLater(dial: Dial): rt.Call; export declare function turned(dial: Dial, turner: Turner): rt.Result; diff --git a/ffi/surface/moq/python.pyi b/ffi/surface/moq/python.pyi index 64bc49059..6e01da979 100644 --- a/ffi/surface/moq/python.pyi +++ b/ffi/surface/moq/python.pyi @@ -1,4 +1,5 @@ # moq.py +__all__ = ['ALPNS', 'AnnounceAnnounce', 'AnnounceConsumer', 'AnnounceEvent', 'ArrayU8x16', 'ArrayU8x2', 'ArrayU8x32', 'ArrayU8x4', 'ArrayU8x6', 'AuthCredential', 'AuthGrant', 'AuthHandle', 'AuthIssued', 'AuthRequest', 'AuthRequests', 'AuthToken', 'AuthTokens', 'AuthWatch', 'BandwidthAllocator', 'BandwidthCap', 'BandwidthConsumer', 'BandwidthDemand', 'BandwidthLimit', 'BandwidthProducer', 'BandwidthRate', 'BandwidthReservation', 'BandwidthViewer', 'BandwidthViewers', 'BandwidthWeak', 'Bound', 'BoundU64', 'BoundsU64', 'BroadcastConsumer', 'BroadcastDatagramRequests', 'BroadcastDemand', 'BroadcastInfo', 'BroadcastKind', 'BroadcastLister', 'BroadcastProducer', 'BroadcastRequests', 'BroadcastTracks', 'BroadcastTracksEvent', 'CACHE_DEFAULT_EXPIRY', 'CacheConfig', 'CachePool', 'CachePoolWeak', 'Client', 'ClockClock', 'ClockDeadline', 'ClockDeadlines', 'ClockElapsed', 'ClockElapsedException', 'ClockEntered', 'ClockInstant', 'ClockInterval', 'ClockManual', 'ClockMissedTickBehavior', 'ClockRng', 'ClockWall', 'ClockWallMap', 'CoopBudget', 'DatagramConsumer', 'DatagramDatagram', 'DatagramInfo', 'DatagramProducer', 'DatagramRequest', 'DecodeError', 'DecodeErrorException', 'Driver', 'Duration', 'EncodeError', 'EncodeErrorException', 'Error', 'ErrorException', 'ForeignReader', 'FrameConsumer', 'FrameFrame', 'FrameInfo', 'FrameProducer', 'GoawayConsumer', 'GoawayGoaway', 'GroupConsumer', 'GroupDemand', 'GroupFetch', 'GroupFinished', 'GroupInfo', 'GroupProducer', 'HANG_CATALOG_MAX_SAFE_INTEGER', 'HANG_CATALOG_PRIORITY', 'HANG_CONTAINER_MAX_AGE', 'HANG_CONTAINER_TIMESCALE', 'HANG_ECHO_SUFFIX', 'HANG_ECHO_TRACK', 'HangCatalog', 'HangCatalogAac', 'HangCatalogAudio', 'HangCatalogAudioCodec', 'HangCatalogAudioCodecKind', 'HangCatalogAudioConfig', 'HangCatalogAudioLayout', 'HangCatalogAv1', 'HangCatalogBinary', 'HangCatalogBinaryConfig', 'HangCatalogChromaticity', 'HangCatalogClock', 'HangCatalogColor', 'HangCatalogColorRange', 'HangCatalogConsumer', 'HangCatalogContainer', 'HangCatalogContentLight', 'HangCatalogDisplay', 'HangCatalogEcho', 'HangCatalogExt', 'HangCatalogExtra', 'HangCatalogH264', 'HangCatalogH265', 'HangCatalogInclude', 'HangCatalogJson', 'HangCatalogJsonConfig', 'HangCatalogMastering', 'HangCatalogMode', 'HangCatalogPriorities', 'HangCatalogProjection', 'HangCatalogSkipped', 'HangCatalogStats', 'HangCatalogStereo', 'HangCatalogText', 'HangCatalogTextConfig', 'HangCatalogTextFormat', 'HangCatalogTextRole', 'HangCatalogTimeline', 'HangCatalogVideo', 'HangCatalogVideoCodec', 'HangCatalogVideoCodecKind', 'HangCatalogVideoConfig', 'HangCatalogVideoProperties', 'HangCatalogVp9', 'HangContainerFrame', 'HangEchoArrival', 'HangEchoRendition', 'HangEchoSnapshot', 'HangError', 'HangErrorException', 'HangStatsRendition', 'HangStatsSnapshot', 'HangStatsTransport', 'IMPLEMENTATION', 'Instance', 'Instant', 'IntersectionError', 'IntersectionErrorException', 'InvalidPattern', 'InvalidPatternException', 'Json', 'Level', 'MUX_CODEC_ANNEXB_START_CODE', 'MUX_CODEC_OPUS_WARMUP', 'MUX_CONTAINER_DELAY_MAX', 'MUX_RATE_RETRY', 'MoqJsonTimedCatalog', 'MoqJsonTimedJson', 'MoqQuicConnectionMuxVersion', 'MoqQuicLimits', 'MoqQuicRate', 'MoqSockDemuxCounters', 'MoqSockDemuxDiscard', 'MoqSockDemuxPin', 'MoqSockUdpEcnCodepoint', 'MoqTokioAcceptFailure', 'MoqTokioAcceptHealth', 'MoqTokioAddrs', 'MoqTokioCliBound', 'MoqTokioCliDeprecated', 'MoqTokioConnectAddr', 'MoqTokioConnectError', 'MoqTokioConnectErrorException', 'MoqTokioConnectResolved', 'MoqTokioConnectionHandover', 'MoqTokioConnectionObservation', 'MoqTokioConnectionPhase', 'MoqTokioConnectionSnapshot', 'MoqTokioListenForward', 'MoqTokioListenLoadBalancer', 'MoqTokioListenReset', 'MoqTokioListenResolved', 'MoqTokioQuicCongestionControl', 'MoqTokioQuicDemuxDatagram', 'MoqTokioQuicDemuxDemux', 'MoqTokioQuicDemuxWebRtc', 'MoqTokioQuicResolved', 'MoqTokioQuicServerId', 'MoqTokioRedirect', 'MoqTokioServerQuicLimits', 'MoqTokioServerStreams', 'MoqTokioTcpConfig', 'MoqTokioTcpTlsAcceptor', 'MoqTokioUnixAllow', 'MoqTokioUnixConfig', 'MoqTokioWebsocketConfig', 'MoqTokioWebsocketError', 'MoqTokioWebsocketErrorException', 'MoqTokioWebsocketListener', 'MoqTokioWebsocketResolved', 'Mut', 'MuxBinding', 'MuxCatalogCatalogFormat', 'MuxCatalogConfig', 'MuxCatalogConfigExt', 'MuxCatalogConfigExtra', 'MuxCatalogConsumer', 'MuxCatalogConsumerExt', 'MuxCatalogConsumerExtra', 'MuxCatalogEstimate', 'MuxCatalogGuard', 'MuxCatalogGuardExt', 'MuxCatalogGuardExtra', 'MuxCatalogHangConsumer', 'MuxCatalogHangConsumerExt', 'MuxCatalogHangConsumerExtra', 'MuxCatalogHangContainer', 'MuxCatalogHangExtra', 'MuxCatalogMsfConsumer', 'MuxCatalogMsfConsumerExt', 'MuxCatalogMsfConsumerExtra', 'MuxCatalogMsfError', 'MuxCatalogProducer', 'MuxCatalogProducerExt', 'MuxCatalogProducerExtra', 'MuxCatalogReserved', 'MuxCatalogReservedExt', 'MuxCatalogReservedExtra', 'MuxCatalogTimebase', 'MuxCatalogTimebaseExt', 'MuxCatalogTimebaseExtra', 'MuxCatalogVideoHint', 'MuxClock', 'MuxCodecAacAdtsError', 'MuxCodecAacAdtsErrorException', 'MuxCodecAacAdtsHeader', 'MuxCodecAacConfig', 'MuxCodecAacError', 'MuxCodecAacErrorException', 'MuxCodecAacImport', 'MuxCodecAacImportException', 'MuxCodecAnnexbError', 'MuxCodecAnnexbErrorException', 'MuxCodecAv1Import', 'MuxCodecAv1ImportException', 'MuxCodecAv1Split', 'MuxCodecFlacConfig', 'MuxCodecFlacError', 'MuxCodecFlacErrorException', 'MuxCodecFlacImport', 'MuxCodecFlacImportException', 'MuxCodecH264Avc1', 'MuxCodecH264Avcc', 'MuxCodecH264Error', 'MuxCodecH264ErrorException', 'MuxCodecH264Import', 'MuxCodecH264ImportException', 'MuxCodecH264Split', 'MuxCodecH264Sps', 'MuxCodecH265Error', 'MuxCodecH265ErrorException', 'MuxCodecH265Hvc1', 'MuxCodecH265Hvcc', 'MuxCodecH265Import', 'MuxCodecH265ImportException', 'MuxCodecH265Split', 'MuxCodecH265Sps', 'MuxCodecH265VideoSignal', 'MuxCodecMp3Config', 'MuxCodecMp3Error', 'MuxCodecMp3ErrorException', 'MuxCodecMp3Import', 'MuxCodecMp3ImportException', 'MuxCodecOpusConfig', 'MuxCodecOpusError', 'MuxCodecOpusErrorException', 'MuxCodecOpusImport', 'MuxCodecOpusImportException', 'MuxCodecOpusMapping', 'MuxCodecVp8Error', 'MuxCodecVp8Import', 'MuxCodecVp8ImportException', 'MuxCodecVp9Error', 'MuxCodecVp9Import', 'MuxCodecVp9ImportException', 'MuxContainerConsumerContainer', 'MuxContainerConsumerFmp4Wire', 'MuxContainerConsumerLegacyWire', 'MuxContainerConsumerLocWire', 'MuxContainerFinishedContainer', 'MuxContainerFinishedContainerAudioConfig', 'MuxContainerFinishedContainerBinaryConfig', 'MuxContainerFinishedContainerJsonConfig', 'MuxContainerFinishedContainerTextConfig', 'MuxContainerFinishedContainerVideoConfig', 'MuxContainerFinishedFmp4Wire', 'MuxContainerFinishedFmp4WireAudioConfig', 'MuxContainerFinishedFmp4WireBinaryConfig', 'MuxContainerFinishedFmp4WireJsonConfig', 'MuxContainerFinishedFmp4WireTextConfig', 'MuxContainerFinishedFmp4WireVideoConfig', 'MuxContainerFinishedLegacyWire', 'MuxContainerFinishedLegacyWireAudioConfig', 'MuxContainerFinishedLegacyWireBinaryConfig', 'MuxContainerFinishedLegacyWireJsonConfig', 'MuxContainerFinishedLegacyWireTextConfig', 'MuxContainerFinishedLegacyWireVideoConfig', 'MuxContainerFinishedLocWire', 'MuxContainerFinishedLocWireAudioConfig', 'MuxContainerFinishedLocWireBinaryConfig', 'MuxContainerFinishedLocWireJsonConfig', 'MuxContainerFinishedLocWireTextConfig', 'MuxContainerFinishedLocWireVideoConfig', 'MuxContainerFlvFinished', 'MuxContainerFlvFinishedExt', 'MuxContainerFlvFinishedExtra', 'MuxContainerFlvImport', 'MuxContainerFlvImportExt', 'MuxContainerFlvImportExtra', 'MuxContainerFmp4Chunk', 'MuxContainerFmp4Error', 'MuxContainerFmp4ErrorException', 'MuxContainerFmp4Finished', 'MuxContainerFmp4FinishedExt', 'MuxContainerFmp4FinishedExtra', 'MuxContainerFmp4Fragment', 'MuxContainerFmp4Import', 'MuxContainerFmp4ImportExt', 'MuxContainerFmp4ImportExtra', 'MuxContainerFmp4Muxer', 'MuxContainerFmp4Wire', 'MuxContainerFrame', 'MuxContainerGroupConsumerContainer', 'MuxContainerGroupConsumerFmp4Wire', 'MuxContainerGroupConsumerLegacyWire', 'MuxContainerGroupConsumerLocWire', 'MuxContainerGuardAudioConfig', 'MuxContainerGuardBinaryConfig', 'MuxContainerGuardJsonConfig', 'MuxContainerGuardTextConfig', 'MuxContainerGuardUnit', 'MuxContainerGuardVideoConfig', 'MuxContainerKind', 'MuxContainerLegacyAudio', 'MuxContainerLegacyWire', 'MuxContainerLocWire', 'MuxContainerMkvFinished', 'MuxContainerMkvFinishedExt', 'MuxContainerMkvFinishedExtra', 'MuxContainerMkvImport', 'MuxContainerMkvImportExt', 'MuxContainerMkvImportExtra', 'MuxContainerMp4Finish', 'MuxContainerPlayout', 'MuxContainerProducerContainer', 'MuxContainerProducerContainerAudioConfig', 'MuxContainerProducerContainerAudioConfigException', 'MuxContainerProducerContainerBinaryConfig', 'MuxContainerProducerContainerBinaryConfigException', 'MuxContainerProducerContainerException', 'MuxContainerProducerContainerJsonConfig', 'MuxContainerProducerContainerJsonConfigException', 'MuxContainerProducerContainerTextConfig', 'MuxContainerProducerContainerTextConfigException', 'MuxContainerProducerContainerVideoConfig', 'MuxContainerProducerContainerVideoConfigException', 'MuxContainerProducerFmp4Wire', 'MuxContainerProducerFmp4WireAudioConfig', 'MuxContainerProducerFmp4WireAudioConfigException', 'MuxContainerProducerFmp4WireBinaryConfig', 'MuxContainerProducerFmp4WireBinaryConfigException', 'MuxContainerProducerFmp4WireException', 'MuxContainerProducerFmp4WireJsonConfig', 'MuxContainerProducerFmp4WireJsonConfigException', 'MuxContainerProducerFmp4WireTextConfig', 'MuxContainerProducerFmp4WireTextConfigException', 'MuxContainerProducerFmp4WireVideoConfig', 'MuxContainerProducerFmp4WireVideoConfigException', 'MuxContainerProducerLegacyWire', 'MuxContainerProducerLegacyWireAudioConfig', 'MuxContainerProducerLegacyWireAudioConfigException', 'MuxContainerProducerLegacyWireBinaryConfig', 'MuxContainerProducerLegacyWireBinaryConfigException', 'MuxContainerProducerLegacyWireException', 'MuxContainerProducerLegacyWireJsonConfig', 'MuxContainerProducerLegacyWireJsonConfigException', 'MuxContainerProducerLegacyWireTextConfig', 'MuxContainerProducerLegacyWireTextConfigException', 'MuxContainerProducerLegacyWireVideoConfig', 'MuxContainerProducerLegacyWireVideoConfigException', 'MuxContainerProducerLocWire', 'MuxContainerProducerLocWireAudioConfig', 'MuxContainerProducerLocWireAudioConfigException', 'MuxContainerProducerLocWireBinaryConfig', 'MuxContainerProducerLocWireBinaryConfigException', 'MuxContainerProducerLocWireException', 'MuxContainerProducerLocWireJsonConfig', 'MuxContainerProducerLocWireJsonConfigException', 'MuxContainerProducerLocWireTextConfig', 'MuxContainerProducerLocWireTextConfigException', 'MuxContainerProducerLocWireVideoConfig', 'MuxContainerProducerLocWireVideoConfigException', 'MuxContainerRead', 'MuxContainerReorderError', 'MuxContainerTimestampRewind', 'MuxContainerTsDescriptor', 'MuxContainerTsError', 'MuxContainerTsErrorException', 'MuxContainerTsExportConsumer', 'MuxContainerTsExportConsumerExt', 'MuxContainerTsExportConsumerExtra', 'MuxContainerTsExt', 'MuxContainerTsFinished', 'MuxContainerTsFinishedExt', 'MuxContainerTsFinishedExtra', 'MuxContainerTsFollower', 'MuxContainerTsFollowerExt', 'MuxContainerTsFollowerExtra', 'MuxContainerTsFraming', 'MuxContainerTsImport', 'MuxContainerTsImportExt', 'MuxContainerTsImportExtra', 'MuxContainerTsMpegts', 'MuxContainerTsPassthrough', 'MuxContainerTsPassthroughExtra', 'MuxContainerTsPassthroughFinished', 'MuxContainerTsPassthroughFinishedExtra', 'MuxContainerTsPassthroughFinishedUnit', 'MuxContainerTsPassthroughTrack', 'MuxContainerTsPassthroughUnit', 'MuxContainerTsPesPacket', 'MuxContainerTsProgram', 'MuxContainerTsPrograms', 'MuxContainerTsProgramsFinished', 'MuxContainerTsRelease', 'MuxContainerTsRepublish', 'MuxContainerTsRepublishFinished', 'MuxContainerTsRepublished', 'MuxContainerTsSiEntry', 'MuxContainerTsStatsClass', 'MuxContainerTsStatsExport', 'MuxContainerTsStatsLog', 'MuxContainerTsStatsRelease', 'MuxContainerTsStatsReport', 'MuxContainerTsStatsSnapshot', 'MuxContainerTsStatsStream', 'MuxContainerTsStep', 'MuxContainerTsTrack', 'MuxContainerTsVerbatim', 'MuxError', 'MuxErrorException', 'MuxFollowInstances', 'MuxImportAudioFormat', 'MuxImportAudioInit', 'MuxImportContainer', 'MuxImportContainerExt', 'MuxImportContainerExtra', 'MuxImportContainerFinished', 'MuxImportContainerFinishedExt', 'MuxImportContainerFinishedExtra', 'MuxImportContainerFormat', 'MuxImportContainerInit', 'MuxImportFormat', 'MuxImportKind', 'MuxImportTrack', 'MuxImportTrackException', 'MuxImportTrackFinished', 'MuxImportTrackStream', 'MuxImportTrackStreamException', 'MuxImportVideoFormat', 'MuxImportVideoInit', 'MuxIngest', 'MuxJsonConfig', 'MuxJsonConsumerJson', 'MuxJsonOptions', 'MuxJsonSnapshotJson', 'MuxJsonSnapshotJsonException', 'MuxJsonStreamJson', 'MuxJsonStreamJsonException', 'MuxLingerUnit', 'MuxPacer', 'MuxRateControl', 'MuxRateGrant', 'MuxRatePolicy', 'MuxRateTarget', 'MuxSelectAudio', 'MuxSelectBroadcast', 'MuxSelectVideo', 'MuxSource', 'MuxSyncConsumer', 'MuxSyncProducer', 'MuxSyncSchedule', 'MuxSyncTrack', 'OriginClaim', 'OriginConfig', 'OriginConsumer', 'OriginCost', 'OriginDriver', 'OriginFollowing', 'OriginLink', 'OriginPriority', 'OriginProducer', 'OriginRequest', 'OriginRoute', 'OriginRouteEvent', 'OriginRouteInfo', 'OriginRouteKind', 'OriginRouteOptions', 'OriginRoutes', 'PATH_MAX_BYTES', 'PATH_MAX_PARTS', 'PATTERN_MAX_INTERSECTIONS', 'PATTERN_MAX_SEGMENTS', 'Park', 'Path', 'PathError', 'PathErrorException', 'PathRelative', 'Pattern', 'Patterns', 'QmuxSession', 'ReconnectBackoff', 'ReconnectConfig', 'ReconnectConfigError', 'ReconnectHandover', 'ReconnectRedirect', 'ReconnectVerdict', 'Retry', 'RustlsCertCompressor', 'RustlsCertDecompressor', 'RustlsClientConfig', 'RustlsClientDangerDangerousClientConfig', 'RustlsClientResumption', 'RustlsClientTicketRequest', 'RustlsClientTls12Resumption', 'RustlsCompressionCache', 'RustlsCryptoHpkeHpkePublicKey', 'RustlsCryptoProvider', 'RustlsDistinguishedName', 'RustlsKeyLog', 'RustlsPkiTypesCertificateDer', 'RustlsPkiTypesDer', 'RustlsPkiTypesTrustAnchor', 'RustlsProtocolVersion', 'RustlsResolvesClientCert', 'RustlsRootCertStore', 'RustlsServerConfig', 'RustlsTimeProvider', 'SERVER_DEFAULT_TIMEOUT', 'SETUP_TOKEN_OUT_OF_BAND', 'Segment', 'Server', 'ServerAdmission', 'ServerAdmitted', 'ServerHandshake', 'Session', 'SessionError', 'SessionLimits', 'SessionStats', 'SetupRole', 'SetupToken', 'Specificity', 'StatsActivity', 'StatsBill', 'StatsConfig', 'StatsContent', 'StatsFailure', 'StatsFailures', 'StatsHandle', 'StatsMessage', 'StatsPresence', 'StatsRefusal', 'StatsRefusalKind', 'StatsRefusals', 'StatsRegistry', 'StatsReport', 'StatsRole', 'StatsRouteClose', 'StatsRouteCloses', 'StatsRouteRefusal', 'StatsRouteRefusals', 'StatsRoutes', 'StatsSession', 'StatsSessionEntry', 'StatsSessionInfo', 'StatsSnapshot', 'StatsTier', 'StatsTotals', 'StatsTraffic', 'StatsTrafficEntry', 'StatsWire', 'StatsWithdrawal', 'StatsWithdrawals', 'StreamError', 'StringException', 'TRANSPORT_MIN_RECEIVE_WINDOW', 'TRANSPORT_SETUP_RECEIVE_WINDOW', 'TimeOverflow', 'TimeOverflowException', 'Timescale', 'Timestamp', 'TokioBackoff', 'TokioClient', 'TokioClientConfig', 'TokioConnectConfig', 'TokioConnectError', 'TokioConnection', 'TokioConnectionMonitor', 'TokioDuration', 'TokioError', 'TokioErrorException', 'TokioListenBind', 'TokioListenConfig', 'TokioLog', 'TokioQuicConfig', 'TokioRestart', 'TokioServer', 'TokioServerConfig', 'TokioServerListener', 'TokioServerRequest', 'TokioStatus', 'TokioTlsCertificates', 'TokioTlsConnect', 'TokioTlsError', 'TokioTlsErrorException', 'TokioTlsIdentity', 'TokioTlsKeyLog', 'TokioTlsListen', 'TokioTlsPeerIdentity', 'TokioTlsServe', 'TokioTransport', 'TrackAbortHandle', 'TrackAnchor', 'TrackCompression', 'TrackConsumer', 'TrackControl', 'TrackDelay', 'TrackDemand', 'TrackFill', 'TrackFinished', 'TrackInfo', 'TrackItem', 'TrackOrder', 'TrackOrdered', 'TrackPosition', 'TrackProducer', 'TrackProducerException', 'TrackRange', 'TrackRefresh', 'TrackRequest', 'TrackRequests', 'TrackSubscriber', 'TrackSubscription', 'TransportAddress', 'TransportCloseKind', 'TransportLimits', 'TransportLimitsError', 'TransportMemoryCloser', 'TransportMemoryConfig', 'TransportMemoryError', 'TransportMemorySession', 'TransportMetrics', 'TransportPollAcked', 'TransportProbe', 'TransportReceiveWindow', 'TransportWire', 'Url', 'Version', 'Versions', 'Waiter', 'WaiterList', 'Waker', 'clock_drive', 'clock_host_time', 'clock_interval', 'clock_interval_at', 'clock_now', 'clock_origin', 'clock_rng', 'clock_seed', 'clock_sleep', 'clock_sleep_until', 'clock_timeout', 'clock_timeout_at', 'clock_wall', 'escape', 'hang_container_track_info', 'hang_echo_is_echo', 'mux_codec_aac_config', 'mux_codec_annexb_after_start_code', 'mux_codec_annexb_build_prefix', 'mux_codec_annexb_find_start_code', 'mux_codec_annexb_from_length_prefixed', 'mux_codec_annexb_length_prefixed_to_annexb', 'mux_codec_flac_config', 'mux_codec_h264_config', 'mux_codec_h265_config', 'mux_codec_mp3_config', 'mux_codec_opus_config', 'mux_codec_opus_packet_samples', 'mux_container_mp4_repair', 'time_run_driver', 'time_run_origin_driver', 'tokio_origin_spawn', 'tokio_tls_parse_fingerprint', 'transport_memory_pair', 'unescape', 'varint_decode_quic', 'varint_encode_quic'] class Waker: def __init__(self, wake: _typing.Callable[[], _object], loop: _asyncio.AbstractEventLoop | None=None) -> None: ... def wake(self) -> None: ... diff --git a/ffi/tests/api.py b/ffi/tests/api.py index b3c82827d..447617313 100644 --- a/ffi/tests/api.py +++ b/ffi/tests/api.py @@ -1328,6 +1328,17 @@ class Tagged(api.Weighted): check(type(e) is RuntimeError and "asyncio" in str(e) and "trio" in str(e), str(e)) e = raised(lambda: api.Waker(lambda: None)) check(type(e) is RuntimeError and "asyncio" in str(e), str(e)) + + # `import *` reaches every export, a `pub fn _deprecated` too, which takes a trailing `_` + # beside the module's own `_deprecated`, and each constant `__getattr__` makes, and no + # import: what the module binds without a leading `_` but its `__future__` import. + star = {} + exec("from api import *", star) + del star["__builtins__"] + check(star["_deprecated_"](1) == 2, "a pub fn named with a leading underscore") + public = {name for name in vars(api) if not name.startswith("_")} - {"annotations"} + expected = public | {"_deprecated_"} | set(api._consts) + check(set(star) == expected, f"import * reaches the exports: {sorted(set(star) ^ expected)}") print("idioms ok") From 11f315226984403a1378a56d4261a949fc90c0de Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Fri, 20 Nov 2026 07:31:17 -0800 Subject: [PATCH 3/8] chore(quest): finish python-private-names Co-Authored-By: Claude Opus 5.5 --- quest/m1/ffi-export/python-private-names.md | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100644 quest/m1/ffi-export/python-private-names.md diff --git a/quest/m1/ffi-export/python-private-names.md b/quest/m1/ffi-export/python-private-names.md deleted file mode 100644 index a72f32066..000000000 --- a/quest/m1/ffi-export/python-private-names.md +++ /dev/null @@ -1,19 +0,0 @@ -# [S] Python: a pub name starting with an underscore passes pyright strict - -## Goal - -A Rust `pub` item whose name starts with `_`, such as `pub fn _deprecated`, generates a -Python module that pyright's strict mode accepts, and the api fixture exports one. - -## Plan - -Decided with the maintainer on 2026-11-19, in the pick of [#900](https://github.com/kixel-ai/rust2/pull/900): ✅ kept, listing every export in the module's `__all__` (rejected: dropping it). - -Found on [kixel-ai/rust2#900](https://github.com/kixel-ai/rust2/pull/900): the module -declares each sync function as a stub under `if _typing.TYPE_CHECKING:` and binds it from -the library in the `else:` branch, so pyright reports a stub named `_x_` as -`reportUnusedFunction`, a private function nothing accesses. - -Recommendation: list every export in the module's `__all__`, which pyright counts as an -access and which makes `from api import *` reach the Rust `pub` items whose names start -with `_` too, as `pub` says they should. From 97dba57fa4a1784c667c685b6aba8b396a15f3ba Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Fri, 20 Nov 2026 07:31:40 -0800 Subject: [PATCH 4/8] style(ffi): rustfmt Co-Authored-By: Claude Opus 5.5 --- ffi/src/python.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ffi/src/python.rs b/ffi/src/python.rs index 7ea03ac16..7582f6644 100644 --- a/ffi/src/python.rs +++ b/ffi/src/python.rs @@ -827,7 +827,8 @@ impl<'a> Gen<'a> { if abi.ranges.values().any(|ty| matches!(ty, Type::Bound(_))) { let bound = abi.rt("bound"); self.register(&bound, "Bound".to_string()); - self.names.insert("Bound".to_string(), "the runtime's range bound".to_string()); + self.names + .insert("Bound".to_string(), "the runtime's range bound".to_string()); self.py.push_str( "class Bound(_enum.Enum):\n\t\"\"\"What a range's start or end bound does: nothing, include its value, or exclude it.\"\"\"\n\n\tUNBOUNDED = 0\n\tINCLUDED = 1\n\tEXCLUDED = 2\n\n\n", ); From 06051246dbe3f8dcc8fd8a1b46e761950169b711 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Fri, 20 Nov 2026 08:05:12 -0800 Subject: [PATCH 5/8] fix(ffi): a Python module-level name Python reserves takes a trailing _ A pub fn __all__ overwrote the module's export list. Every __x__ name now takes a trailing _, as other taken names do. Adds a follow-up for C++, which reserves such names too. Co-Authored-By: Claude Opus 5.5 --- ffi/fixtures/api/src/lib.rs | 5 +++++ ffi/src/python.rs | 9 +++++++-- ffi/surface/api/c.h | 3 ++- ffi/surface/api/cpp.hpp | 1 + ffi/surface/api/dart.dart | 1 + ffi/surface/api/go.txt | 1 + ffi/surface/api/kotlin.kt | 1 + ffi/surface/api/python.pyi | 3 ++- ffi/surface/api/swift.swift | 1 + ffi/surface/api/web.d.ts | 1 + ffi/tests/api.py | 10 ++++++---- quest/m1/ffi-export/cpp-reserved-names.md | 21 +++++++++++++++++++++ 12 files changed, 49 insertions(+), 8 deletions(-) create mode 100644 quest/m1/ffi-export/cpp-reserved-names.md diff --git a/ffi/fixtures/api/src/lib.rs b/ffi/fixtures/api/src/lib.rs index d44bec63f..30335cb80 100644 --- a/ffi/fixtures/api/src/lib.rs +++ b/ffi/fixtures/api/src/lib.rs @@ -5381,6 +5381,11 @@ pub fn _deprecated(note: u8) -> u8 { note + 1 } +/// Two more than `note`, by a name Python reserves, as the module's own `__all__` is. +pub fn __all__(note: u8) -> u8 { + note + 2 +} + /// A dial, whose docs carry each rustdoc form a binding renders as its own: links to a /// method [`Self::turn`], a field [`Dial::level`], a variant [`Error::Overflow`], a /// function [`advance`], a constant [`LIMIT`], an object [`Counter`], a callback's method diff --git a/ffi/src/python.rs b/ffi/src/python.rs index 7582f6644..c35c4fc9c 100644 --- a/ffi/src/python.rs +++ b/ffi/src/python.rs @@ -517,9 +517,14 @@ impl<'a> Gen<'a> { self.classes.get(c).cloned().unwrap_or_else(|| pascal(self.bare(c))) } - /// The module-level Python name `what` takes, `name` unless that is taken. + /// The module-level Python name `what` takes, `name` unless that is taken. Python + /// defines `__x__` names, such as the module's own `__all__` and `__getattr__`, which + /// one takes a trailing `_` past. fn claim(&mut self, name: &str, what: String) -> String { - abi::claim(&mut self.names, |_| false, name, what) + let dunder = |name: &str| { + name.len() > 4 && name.starts_with("__") && name.ends_with("__") && !name.ends_with("___") + }; + abi::claim(&mut self.names, dunder, name, what) } /// Register the class the Python expression `py` names under `key`, returning the diff --git a/ffi/surface/api/c.h b/ffi/surface/api/c.h index 84c120459..443533104 100644 --- a/ffi/surface/api/c.h +++ b/ffi/surface/api/c.h @@ -17,7 +17,7 @@ #ifdef __cplusplus extern "C" { #endif -#define API_CONTRACT ((uint64_t)0x63394d403cb27cc7ULL) +#define API_CONTRACT ((uint64_t)0xdeea008993534300ULL) uint64_t api_contract(void); uint32_t api_target(void); typedef int32_t api_status; @@ -2486,6 +2486,7 @@ void api_unescaped_maybe_future_free(api_unescaped_maybe_future *future); API_MUST_USE api_buf api_unzeroed(api_buf bytes); uint8_t api_deprecated(uint8_t note); uint8_t api__deprecated(uint8_t note); +uint8_t api___all__(uint8_t note); api_Knob api_knob(api_Dial dial); typedef struct api_level_later_future api_level_later_future; API_MUST_USE api_level_later_future *api_level_later(api_Dial dial); diff --git a/ffi/surface/api/cpp.hpp b/ffi/surface/api/cpp.hpp index f0182d99d..d19e7b05e 100644 --- a/ffi/surface/api/cpp.hpp +++ b/ffi/surface/api/cpp.hpp @@ -1787,6 +1787,7 @@ namespace api { inline ::api::buf unzeroed(::api::input bytes); inline ::std::uint8_t deprecated(::std::uint8_t note); inline ::std::uint8_t _deprecated(::std::uint8_t note); + inline ::std::uint8_t __all__(::std::uint8_t note); [[deprecated]] inline ::api::Knob knob(const ::api::Dial &dial); [[deprecated("read its `level`")]] inline ::api::level_later_future level_later(const ::api::Dial &dial); inline ::api::result<::api::Dial, ::api::Error> turned(const ::api::Dial &dial, ::std::unique_ptr<::api::Turner> turner); diff --git a/ffi/surface/api/dart.dart b/ffi/surface/api/dart.dart index 28ece4ee1..7035ca686 100644 --- a/ffi/surface/api/dart.dart +++ b/ffi/surface/api/dart.dart @@ -1935,6 +1935,7 @@ Cancelable unescapedMaybe(String? text); typed.Uint8List unzeroed(typed.Uint8List bytes); int deprecated(int note); int deprecated_(int note); +int all(int note); @Deprecated('') Knob knob(Dial dial); @Deprecated('read its `level`') Cancelable levelLater(Dial dial); Dial turned(Dial dial, Turner turner); diff --git a/ffi/surface/api/go.txt b/ffi/surface/api/go.txt index f748fad40..6ebe7c8f6 100644 --- a/ffi/surface/api/go.txt +++ b/ffi/surface/api/go.txt @@ -9,6 +9,7 @@ const URL uint64 = 1000 FUNCTIONS func Admit(entry p_rt.Tuple4[*Counter, *Mark, Seat, Choice]) (uint64, error) func After(ctx context.Context, first func(context.Context), value uint32) (uint32, error) +func All(note uint8) uint8 func Alpn(config *p_tls.Config) (string, error) func AlpnLent(config *p_tls.Config) (string, error) func ApplyNonZeroU16(pair PairNonZeroU16, f func(uint16) uint32) (uint32, error) diff --git a/ffi/surface/api/kotlin.kt b/ffi/surface/api/kotlin.kt index 8a033b566..c41473f22 100644 --- a/ffi/surface/api/kotlin.kt +++ b/ffi/surface/api/kotlin.kt @@ -1679,6 +1679,7 @@ suspend fun unescapedMaybe(text: kotlin.String?): kotlin.String? fun unzeroed(bytes: api.Bytes): api.Bytes fun deprecated(note: kotlin.UByte): kotlin.UByte fun deprecated_(note: kotlin.UByte): kotlin.UByte +fun all(note: kotlin.UByte): kotlin.UByte @kotlin.Deprecated("") fun knob(dial: api.Dial): api.Knob @kotlin.Deprecated("read its `level`") suspend fun levelLater(dial: api.Dial): kotlin.ULong @kotlin.jvm.Throws(ErrorException::class) fun turned(dial: api.Dial, turner: api.Turner): api.Dial diff --git a/ffi/surface/api/python.pyi b/ffi/surface/api/python.pyi index e4b938c50..fb80e1ad1 100644 --- a/ffi/surface/api/python.pyi +++ b/ffi/surface/api/python.pyi @@ -1,5 +1,5 @@ # api.py -__all__ = ['A', 'Area', 'Array', 'ArrayU8x4', 'Atlas', 'B', 'BOXED', 'Batch', 'Batch2', 'Beat', 'Berth', 'Board', 'Booth', 'Bound', 'BoundU64', 'BoundsU64', 'BoundsU64Exception', 'BoxedU16', 'BoxedU8', 'Builtin', 'C', 'CancellationError', 'Cancelled', 'Channel', 'Choice', 'Clash', 'ClashAny', 'ClashBreak', 'ClashCandidate', 'ClashEmptyString', 'ClashEscaped', 'ClashSeed', 'ClashSpan', 'ClashStore', 'ClashTone', 'ClashTone_', 'Clocked', 'Codecs', 'Core', 'Countdown', 'Counter', 'Cursor', 'Deprecated', 'Der', 'Dial', 'Digest', 'DoubleArray', 'Draft', 'Duration', 'Error', 'ErrorException', 'Event', 'Extent', 'FAR', 'Family', 'Fault', 'FaultException', 'Feed', 'FiledReceipt', 'ForeignReader', 'Forged', 'GREETINGS', 'Gap', 'Gauge', 'Handle', 'Hasher', 'Hits', 'Holder', 'Hooked', 'InnerU8', 'Instant', 'Journal', 'Json', 'JvmField', 'JvmStatic', 'Key', 'Knob', 'LIMIT', 'Label', 'Labeled', 'Labelled', 'Latch', 'Layered', 'Ledger', 'LeftRightU8', 'LeftU8', 'Level', 'LimitsBytes', 'LimitsDuration', 'ListClashToneException', 'Local', 'LocalWaiter', 'Log', 'LogCount', 'LogThread', 'Logger', 'LongArray', 'MacrosStreams', 'Mark', 'Marker', 'Measure', 'Message', 'Meter', 'Meters', 'Moment', 'Mut', 'Name', 'Node', 'NonZeros', 'Note', 'Numbers', 'OptIn', 'OuterInnerU8', 'PRIMES', 'Packaged', 'Packet', 'PadU16', 'PadU8', 'Page', 'PairNonZeroU16', 'PairSizeU8', 'PairU32', 'PairU8Size', 'Parcel', 'Part', 'Pass', 'Peer', 'Pinned', 'Placement', 'Plain', 'Platform', 'Point', 'PolarPoint', 'PolarTurn', 'Polar_Turn', 'Qualifiers', 'Quantity', 'Rank', 'Rated', 'Reading', 'Receipt', 'Refusal', 'RefusalException', 'Registry', 'Resolving', 'Retired', 'Retry', 'RightLeftU8', 'RightU8', 'STEP', 'Scan', 'Score', 'Seat', 'Shadowed', 'Shape', 'Sheet', 'Site', 'Size', 'Slip', 'SlotU32', 'SlotU8', 'Span', 'Spawned', 'Spot', 'Stack', 'Stage', 'Stamp', 'Stamped', 'StartSeekable', 'Status', 'StdIoError', 'StringException', 'Tab', 'Tallies', 'Tally', 'Ticket', 'Tier', 'TlsCert', 'TlsCodec', 'TlsConfig', 'TlsPolicyLifetime', 'TlsResolver', 'TlsSession', 'Token', 'Trail', 'Turner', 'URL', 'Url', 'VecClashTone', 'Verbosity', 'Version', 'Waiter', 'Waker', 'Weighted', 'Wide', 'Window', 'Worker', 'WrapU32', '_deprecated_', 'admit', 'advance', 'after', 'alpn', 'alpn_lent', 'apply_non_zero_u16', 'apply_u32', 'area', 'assert_', 'attempt', 'beats', 'below', 'booth_count', 'boxed_counter', 'boxed_floats', 'boxed_name', 'boxed_tuple', 'breadth', 'bump_both', 'bump_either', 'byte_len', 'byte_limits', 'capacities_2_2', 'capacities_2_4', 'capacities_4_2', 'capacities_4_4', 'cert_der', 'cert_len', 'certify', 'chain_len', 'choose', 'chunks', 'clash_any', 'clash_audible', 'clash_audio_encoder_finish', 'clash_audio_encoder_finish_', 'clash_candidate', 'clash_empty', 'clash_ignore', 'clash_nested', 'clocked_after', 'coordinates', 'corner', 'corner_later', 'count', 'counted', 'counters', 'crammed', 'cross', 'crowded', 'deprecated', 'describe', 'describe_non_zeros', 'digit', 'divide', 'doubled', 'doubled_i64', 'doubled_ttl', 'drain_2', 'drain_4', 'drive', 'dropped', 'each', 'either', 'either_later', 'emit', 'emit_from_thread', 'emit_later', 'encode', 'end', 'ends', 'entries', 'erased', 'errno', 'excuse', 'extended', 'failure', 'failure_kind', 'failure_message', 'farther_hop', 'file', 'fill_2', 'fill_4', 'filter', 'find', 'fingerprint', 'first_of', 'flip', 'greet', 'grow', 'halved', 'halves', 'has_instant', 'has_text', 'heft', 'held_count', 'hex', 'hook', 'host', 'is_family', 'is_kept', 'jam', 'jni_one', 'join_words', 'joined', 'jvm_sum', 'keep_point', 'keeper_point', 'keeps', 'kept_counter', 'kept_or_point', 'kept_point', 'kept_polar_point', 'kept_size', 'kept_wrap_u32', 'knob', 'lasting', 'later', 'layer_name', 'least', 'len', 'lent_back', 'less', 'level_later', 'local_after', 'local_later', 'local_or_new', 'local_or_new_later', 'locals_dropped', 'log_counts', 'log_later', 'log_on_drop', 'log_waker', 'longer', 'longest', 'louder', 'macros_streamed', 'made', 'marked', 'moment_at', 'named', 'next_char', 'next_hop', 'next_ips', 'next_packet', 'nexts', 'non_zeros', 'now', 'nudge', 'nudge_by', 'numbered', 'offered_len', 'offset', 'offsetof', 'on_first_thread', 'only', 'page', 'pair', 'parents', 'parse_cert', 'parse_later', 'peek', 'placement', 'platform', 'pointer_bits', 'polar_point', 'poll_tripled', 'port', 'ports', 'prefixed', 'push_counted', 'put_number', 'queued_hex', 'reach', 'read_len', 'reading', 'reading_bump', 'reading_debug', 'reading_echo', 'reasons', 'refuse', 'reissue', 'reissue_lent', 'relay', 'report_non_zero_u16', 'report_u32', 'resolve', 'resolved', 'resolver', 'resume', 'return_moved', 'return_values', 'rooted_name', 'rows', 'same', 'same_char', 'same_duration', 'same_ip_addr', 'same_isize', 'same_labelled', 'same_path', 'same_socket_addr', 'same_socket_addr_v4', 'same_socket_addr_v6', 'same_string', 'same_u128', 'same_u64', 'same_usize', 'sample_hex', 'scaled', 'scanned', 'seat', 'second_later', 'sections', 'secure', 'seeds_counter_counter', 'seeds_counter_point', 'seeds_counter_polar_point', 'seeds_counter_size', 'seeds_counter_wrap_u32', 'seeds_point_counter', 'seeds_point_point', 'seeds_point_polar_point', 'seeds_point_size', 'seeds_point_wrap_u32', 'seek_to', 'sentence', 'shift', 'shifted', 'since', 'span', 'spell', 'spend', 'split_last', 'spread', 'stamp_at', 'stored', 'stored_text', 'stray', 'sum_all', 'sum_lists', 'sum_u32', 'summed', 'summed_up_receipt', 'sums', 'swapped', 'tag', 'tagged', 'tail', 'tallied', 'tally_log_count', 'tick_name', 'tickets', 'timed_hex', 'title', 'token_bytes', 'token_slice', 'total', 'turned', 'unescaped', 'unescaped_later', 'unescaped_maybe', 'unhook', 'unnamed', 'unzeroed', 'verify', 'visit_chunks', 'visit_stray', 'walk', 'wasm_log', 'wasm_only', 'wasm_take', 'watch', 'weigh_all_counter', 'weigh_point', 'wide', 'widen', 'widths', 'wind', 'within', 'words', 'worth', 'yielded'] +__all__ = ['A', 'Area', 'Array', 'ArrayU8x4', 'Atlas', 'B', 'BOXED', 'Batch', 'Batch2', 'Beat', 'Berth', 'Board', 'Booth', 'Bound', 'BoundU64', 'BoundsU64', 'BoundsU64Exception', 'BoxedU16', 'BoxedU8', 'Builtin', 'C', 'CancellationError', 'Cancelled', 'Channel', 'Choice', 'Clash', 'ClashAny', 'ClashBreak', 'ClashCandidate', 'ClashEmptyString', 'ClashEscaped', 'ClashSeed', 'ClashSpan', 'ClashStore', 'ClashTone', 'ClashTone_', 'Clocked', 'Codecs', 'Core', 'Countdown', 'Counter', 'Cursor', 'Deprecated', 'Der', 'Dial', 'Digest', 'DoubleArray', 'Draft', 'Duration', 'Error', 'ErrorException', 'Event', 'Extent', 'FAR', 'Family', 'Fault', 'FaultException', 'Feed', 'FiledReceipt', 'ForeignReader', 'Forged', 'GREETINGS', 'Gap', 'Gauge', 'Handle', 'Hasher', 'Hits', 'Holder', 'Hooked', 'InnerU8', 'Instant', 'Journal', 'Json', 'JvmField', 'JvmStatic', 'Key', 'Knob', 'LIMIT', 'Label', 'Labeled', 'Labelled', 'Latch', 'Layered', 'Ledger', 'LeftRightU8', 'LeftU8', 'Level', 'LimitsBytes', 'LimitsDuration', 'ListClashToneException', 'Local', 'LocalWaiter', 'Log', 'LogCount', 'LogThread', 'Logger', 'LongArray', 'MacrosStreams', 'Mark', 'Marker', 'Measure', 'Message', 'Meter', 'Meters', 'Moment', 'Mut', 'Name', 'Node', 'NonZeros', 'Note', 'Numbers', 'OptIn', 'OuterInnerU8', 'PRIMES', 'Packaged', 'Packet', 'PadU16', 'PadU8', 'Page', 'PairNonZeroU16', 'PairSizeU8', 'PairU32', 'PairU8Size', 'Parcel', 'Part', 'Pass', 'Peer', 'Pinned', 'Placement', 'Plain', 'Platform', 'Point', 'PolarPoint', 'PolarTurn', 'Polar_Turn', 'Qualifiers', 'Quantity', 'Rank', 'Rated', 'Reading', 'Receipt', 'Refusal', 'RefusalException', 'Registry', 'Resolving', 'Retired', 'Retry', 'RightLeftU8', 'RightU8', 'STEP', 'Scan', 'Score', 'Seat', 'Shadowed', 'Shape', 'Sheet', 'Site', 'Size', 'Slip', 'SlotU32', 'SlotU8', 'Span', 'Spawned', 'Spot', 'Stack', 'Stage', 'Stamp', 'Stamped', 'StartSeekable', 'Status', 'StdIoError', 'StringException', 'Tab', 'Tallies', 'Tally', 'Ticket', 'Tier', 'TlsCert', 'TlsCodec', 'TlsConfig', 'TlsPolicyLifetime', 'TlsResolver', 'TlsSession', 'Token', 'Trail', 'Turner', 'URL', 'Url', 'VecClashTone', 'Verbosity', 'Version', 'Waiter', 'Waker', 'Weighted', 'Wide', 'Window', 'Worker', 'WrapU32', '__all___', '_deprecated_', 'admit', 'advance', 'after', 'alpn', 'alpn_lent', 'apply_non_zero_u16', 'apply_u32', 'area', 'assert_', 'attempt', 'beats', 'below', 'booth_count', 'boxed_counter', 'boxed_floats', 'boxed_name', 'boxed_tuple', 'breadth', 'bump_both', 'bump_either', 'byte_len', 'byte_limits', 'capacities_2_2', 'capacities_2_4', 'capacities_4_2', 'capacities_4_4', 'cert_der', 'cert_len', 'certify', 'chain_len', 'choose', 'chunks', 'clash_any', 'clash_audible', 'clash_audio_encoder_finish', 'clash_audio_encoder_finish_', 'clash_candidate', 'clash_empty', 'clash_ignore', 'clash_nested', 'clocked_after', 'coordinates', 'corner', 'corner_later', 'count', 'counted', 'counters', 'crammed', 'cross', 'crowded', 'deprecated', 'describe', 'describe_non_zeros', 'digit', 'divide', 'doubled', 'doubled_i64', 'doubled_ttl', 'drain_2', 'drain_4', 'drive', 'dropped', 'each', 'either', 'either_later', 'emit', 'emit_from_thread', 'emit_later', 'encode', 'end', 'ends', 'entries', 'erased', 'errno', 'excuse', 'extended', 'failure', 'failure_kind', 'failure_message', 'farther_hop', 'file', 'fill_2', 'fill_4', 'filter', 'find', 'fingerprint', 'first_of', 'flip', 'greet', 'grow', 'halved', 'halves', 'has_instant', 'has_text', 'heft', 'held_count', 'hex', 'hook', 'host', 'is_family', 'is_kept', 'jam', 'jni_one', 'join_words', 'joined', 'jvm_sum', 'keep_point', 'keeper_point', 'keeps', 'kept_counter', 'kept_or_point', 'kept_point', 'kept_polar_point', 'kept_size', 'kept_wrap_u32', 'knob', 'lasting', 'later', 'layer_name', 'least', 'len', 'lent_back', 'less', 'level_later', 'local_after', 'local_later', 'local_or_new', 'local_or_new_later', 'locals_dropped', 'log_counts', 'log_later', 'log_on_drop', 'log_waker', 'longer', 'longest', 'louder', 'macros_streamed', 'made', 'marked', 'moment_at', 'named', 'next_char', 'next_hop', 'next_ips', 'next_packet', 'nexts', 'non_zeros', 'now', 'nudge', 'nudge_by', 'numbered', 'offered_len', 'offset', 'offsetof', 'on_first_thread', 'only', 'page', 'pair', 'parents', 'parse_cert', 'parse_later', 'peek', 'placement', 'platform', 'pointer_bits', 'polar_point', 'poll_tripled', 'port', 'ports', 'prefixed', 'push_counted', 'put_number', 'queued_hex', 'reach', 'read_len', 'reading', 'reading_bump', 'reading_debug', 'reading_echo', 'reasons', 'refuse', 'reissue', 'reissue_lent', 'relay', 'report_non_zero_u16', 'report_u32', 'resolve', 'resolved', 'resolver', 'resume', 'return_moved', 'return_values', 'rooted_name', 'rows', 'same', 'same_char', 'same_duration', 'same_ip_addr', 'same_isize', 'same_labelled', 'same_path', 'same_socket_addr', 'same_socket_addr_v4', 'same_socket_addr_v6', 'same_string', 'same_u128', 'same_u64', 'same_usize', 'sample_hex', 'scaled', 'scanned', 'seat', 'second_later', 'sections', 'secure', 'seeds_counter_counter', 'seeds_counter_point', 'seeds_counter_polar_point', 'seeds_counter_size', 'seeds_counter_wrap_u32', 'seeds_point_counter', 'seeds_point_point', 'seeds_point_polar_point', 'seeds_point_size', 'seeds_point_wrap_u32', 'seek_to', 'sentence', 'shift', 'shifted', 'since', 'span', 'spell', 'spend', 'split_last', 'spread', 'stamp_at', 'stored', 'stored_text', 'stray', 'sum_all', 'sum_lists', 'sum_u32', 'summed', 'summed_up_receipt', 'sums', 'swapped', 'tag', 'tagged', 'tail', 'tallied', 'tally_log_count', 'tick_name', 'tickets', 'timed_hex', 'title', 'token_bytes', 'token_slice', 'total', 'turned', 'unescaped', 'unescaped_later', 'unescaped_maybe', 'unhook', 'unnamed', 'unzeroed', 'verify', 'visit_chunks', 'visit_stray', 'walk', 'wasm_log', 'wasm_only', 'wasm_take', 'watch', 'weigh_all_counter', 'weigh_point', 'wide', 'widen', 'widths', 'wind', 'within', 'words', 'worth', 'yielded'] class Waker: def __init__(self, wake: _typing.Callable[[], _object], loop: _asyncio.AbstractEventLoop | None=None) -> None: ... def wake(self) -> None: ... @@ -1738,6 +1738,7 @@ def same_ip_addr(v: _ipaddress.IPv4Address | _ipaddress.IPv6Address) -> _ipaddre def unescaped(text: _str) -> _str: ... def unzeroed(bytes: _bytes | _bytearray | _memoryview) -> _memoryview: ... def deprecated(note: _int) -> _int: ... +def __all___(note: _int) -> _int: ... @_deprecated('') def knob(dial: Dial) -> Knob: ... def turned(dial: Dial, turner: Turner) -> Dial: ... diff --git a/ffi/surface/api/swift.swift b/ffi/surface/api/swift.swift index 0a8d2ffe3..b39bdaf7e 100644 --- a/ffi/surface/api/swift.swift +++ b/ffi/surface/api/swift.swift @@ -1761,6 +1761,7 @@ public let URL: Swift.UInt64 @inlinable public func unzeroed(_ bytes: borrowing Swift.Span) -> Bytes @inlinable public func deprecated(_ note: Swift.UInt8) -> Swift.UInt8 @inlinable public func deprecated_(_ note: Swift.UInt8) -> Swift.UInt8 +@inlinable public func all(_ note: Swift.UInt8) -> Swift.UInt8 @available(*, deprecated) @inlinable public func knob(_ dial: Dial) -> Knob @available(*, deprecated, message: "read its `level`") @inlinable nonisolated(nonsending) public func levelLater(_ dial: Dial) async throws -> Swift.UInt64 @inlinable public func turned(_ dial: Dial, _ turner: any Turner) throws -> Dial diff --git a/ffi/surface/api/web.d.ts b/ffi/surface/api/web.d.ts index 18dfe9337..21934451f 100644 --- a/ffi/surface/api/web.d.ts +++ b/ffi/surface/api/web.d.ts @@ -2747,6 +2747,7 @@ export declare function unescapedMaybe(text: string | undefined): rt.Call; export declare function turned(dial: Dial, turner: Turner): rt.Result; diff --git a/ffi/tests/api.py b/ffi/tests/api.py index 447617313..a683a67bd 100644 --- a/ffi/tests/api.py +++ b/ffi/tests/api.py @@ -1329,15 +1329,17 @@ class Tagged(api.Weighted): e = raised(lambda: api.Waker(lambda: None)) check(type(e) is RuntimeError and "asyncio" in str(e), str(e)) - # `import *` reaches every export, a `pub fn _deprecated` too, which takes a trailing `_` - # beside the module's own `_deprecated`, and each constant `__getattr__` makes, and no - # import: what the module binds without a leading `_` but its `__future__` import. + # `import *` reaches every export: a `pub fn _deprecated` too, which takes a trailing `_` + # beside the module's own `_deprecated`, as `pub fn __all__` does beside the name Python + # reserves, and each constant `__getattr__` makes; and no import: what the module binds + # without a leading `_` but its `__future__` import. star = {} exec("from api import *", star) del star["__builtins__"] check(star["_deprecated_"](1) == 2, "a pub fn named with a leading underscore") + check(star["__all___"](1) == 3, "a pub fn named as a name Python reserves") public = {name for name in vars(api) if not name.startswith("_")} - {"annotations"} - expected = public | {"_deprecated_"} | set(api._consts) + expected = public | {"_deprecated_", "__all___"} | set(api._consts) check(set(star) == expected, f"import * reaches the exports: {sorted(set(star) ^ expected)}") print("idioms ok") diff --git a/quest/m1/ffi-export/cpp-reserved-names.md b/quest/m1/ffi-export/cpp-reserved-names.md new file mode 100644 index 000000000..a83ba73b6 --- /dev/null +++ b/quest/m1/ffi-export/cpp-reserved-names.md @@ -0,0 +1,21 @@ +# [S] C++: a Rust name C++ reserves exports under one it does not + +## Goal + +A Rust `pub` item whose name C++ reserves for the implementation, one holding `__` anywhere +or starting with `_` and a capital, such as the api fixture's `pub fn __all__`, exports in +C++ under a name the standard leaves to programs ([lex.name]), and `tests/api_strict.cpp` +builds with clang's `-Wreserved-identifier` on. + +## Plan + +Found on [kixel-ai/rust2#925](https://github.com/kixel-ai/rust2/pull/925), whose fixture's +`pub fn __all__` renders in `ffi/surface/api/cpp.hpp` as `api::__all__`: it compiles, but +a name the implementation reserves may break on any standard library. Rust's own +`#[doc(hidden)] pub` macro support, such as `__private_api`, takes such names too. + +Recommendation: give the name the trailing `_` C++'s other escapes take only where that +clears the reservation; otherwise drop leading underscores and collapse each `__` to `_`, +then claim the result through `named` in `ffi/src/cpp.rs` as any other name, so +`__all__` and an `all` stay apart. Turn on `-Wreserved-identifier` in the strict build to +keep it so. From 42231061caa89acf34b6e4663ab288b591a758e3 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Fri, 20 Nov 2026 08:07:23 -0800 Subject: [PATCH 6/8] style(ffi): rustfmt Co-Authored-By: Claude Opus 5.5 --- ffi/src/python.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ffi/src/python.rs b/ffi/src/python.rs index c35c4fc9c..1c4317ed7 100644 --- a/ffi/src/python.rs +++ b/ffi/src/python.rs @@ -521,9 +521,8 @@ impl<'a> Gen<'a> { /// defines `__x__` names, such as the module's own `__all__` and `__getattr__`, which /// one takes a trailing `_` past. fn claim(&mut self, name: &str, what: String) -> String { - let dunder = |name: &str| { - name.len() > 4 && name.starts_with("__") && name.ends_with("__") && !name.ends_with("___") - }; + let dunder = + |name: &str| name.len() > 4 && name.starts_with("__") && name.ends_with("__") && !name.ends_with("___"); abi::claim(&mut self.names, dunder, name, what) } From 0e1fb0b996b7a3f88e58bd5aa8964df3111dd94d Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Fri, 20 Nov 2026 08:22:05 -0800 Subject: [PATCH 7/8] quest: record the maintainer's follow-up answers Co-Authored-By: Claude Opus 5.5 --- quest/m1/ffi-export/cpp-reserved-names.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/quest/m1/ffi-export/cpp-reserved-names.md b/quest/m1/ffi-export/cpp-reserved-names.md index a83ba73b6..224f51e6b 100644 --- a/quest/m1/ffi-export/cpp-reserved-names.md +++ b/quest/m1/ffi-export/cpp-reserved-names.md @@ -9,6 +9,8 @@ builds with clang's `-Wreserved-identifier` on. ## Plan +Decided with the maintainer on 2026-11-19, in the pick of [#925](https://github.com/kixel-ai/rust2/pull/925): ✅ kept, escaping reserved names in C++ and turning on clang's `-Wreserved-identifier` in the strict build (rejected: dropping it). + Found on [kixel-ai/rust2#925](https://github.com/kixel-ai/rust2/pull/925), whose fixture's `pub fn __all__` renders in `ffi/surface/api/cpp.hpp` as `api::__all__`: it compiles, but a name the implementation reserves may break on any standard library. Rust's own From 2b83610f48cb17bae1ace39cccdb053d881ad638 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Fri, 20 Nov 2026 08:43:55 -0800 Subject: [PATCH 8/8] fix(ffi): a Python export named _inspect takes a trailing _ The generated module imports inspect as _inspect for the runtime's isawaitable check, but TAKEN missed it. Hoist the imports into IMPORTS and test that every alias it binds, and every _ name the runtime binds at module level, is in TAKEN. Co-Authored-By: Claude Opus 5.5 --- ffi/src/python.rs | 113 ++++++++++++++++++++++++++++------------------ 1 file changed, 69 insertions(+), 44 deletions(-) diff --git a/ffi/src/python.rs b/ffi/src/python.rs index 1acf1baa1..3bc476ab9 100644 --- a/ffi/src/python.rs +++ b/ffi/src/python.rs @@ -84,6 +84,7 @@ const TAKEN: &[&str] = &[ "_zip", "_datetime", "_ipaddress", + "_inspect", "_enum", "_socket", "_sys", @@ -112,6 +113,51 @@ const TAKEN: &[&str] = &[ "Duration", ]; +/// The modules and builtins the generated Python names, each under a `_` alias [`TAKEN`] holds. +const IMPORTS: &str = "\ + import abc as _abc\n\ + import array as _array\n\ + import asyncio as _asyncio\n\ + import datetime as _datetime\n\ + import ipaddress as _ipaddress\n\ + import enum as _enum\n\ + import inspect as _inspect\n\ + import socket as _socket\n\ + import sys as _sys\n\ + import typing as _typing\n\ + import weakref as _weakref\n\ + from builtins import AttributeError as _AttributeError\n\ + from builtins import BaseException as _BaseException\n\ + from builtins import Exception as _Exception\n\ + from builtins import ImportError as _ImportError\n\ + from builtins import NotImplemented as _NotImplemented\n\ + from builtins import NotImplementedError as _NotImplementedError\n\ + from builtins import RuntimeError as _RuntimeError\n\ + from builtins import StopAsyncIteration as _StopAsyncIteration\n\ + from builtins import TypeError as _TypeError\n\ + from builtins import ValueError as _ValueError\n\ + from builtins import all as _all\n\ + from builtins import any as _any\n\ + from builtins import bool as _bool\n\ + from builtins import bytearray as _bytearray\n\ + from builtins import bytes as _bytes\n\ + from builtins import dict as _dict\n\ + from builtins import float as _float\n\ + from builtins import getattr as _getattr\n\ + from builtins import int as _int\n\ + from builtins import isinstance as _isinstance\n\ + from builtins import len as _len\n\ + from builtins import list as _list\n\ + from builtins import memoryview as _memoryview\n\ + from builtins import object as _object\n\ + from builtins import property as _property\n\ + from builtins import range as _range\n\ + from builtins import staticmethod as _staticmethod\n\ + from builtins import str as _str\n\ + from builtins import tuple as _tuple\n\ + from builtins import type as _type\n\ + from builtins import zip as _zip\n\n"; + /// The module's `@_deprecated`, which `TAKEN` keeps an export from shadowing. const DEPRECATOR: &str = "_T = _typing.TypeVar(\"_T\")\n\nif _typing.TYPE_CHECKING:\n\tfrom typing_extensions import deprecated as _deprecated\nelse:\n\n\tdef _deprecated(message: _str, /) -> _typing.Callable[[_T], _T]:\n\t\t\"\"\"Marks a deprecated item for type checkers.\"\"\"\n\t\treturn lambda item: item\n"; @@ -213,49 +259,7 @@ pub(crate) fn generate(abi: &Abi<'_>, packages: &str, contract: u64) -> Result 1) + }); + for name in aliases.chain(bound) { + assert!(TAKEN.contains(&name), "the module's `{name}` is not in TAKEN"); + } + } + /// Every name the deprecation helper binds is taken, so no export shadows it. #[test] fn deprecator_names_taken() {