Charlie Marsh
08aac42edb
Coalesce source slices when formatting attributes ( #29841 )
...
## Summary
Formatting and printing the top-level modules in CPython’s standard
library took 3.9% less time in a local benchmark (125.7 ms to 120.8 ms),
or 2.4% less with parsing included. CodSpeed reports a 5.1% efficiency
improvement on the [`large/dataset.py` formatter
benchmark](https://github.com/astral-sh/ruff/pull/29841#issuecomment-6515803489 ).
Today the formatter emits a source slice for `a`, a dot token, and a
source slice for `b` just to print `a.b`. We now emit the whole
expression as one slice when the dot touches both names, the first name
is unparenthesized, and there are no comments or call-chain breaks to
handle. Reading directly from the source also preserves Unicode
spellings like `𝓪.𝓫`.
For `factory().attr`, we still format the call and handle any line break
before the dot, but we can emit `.attr` as one slice. This follows the
approach in [Oxc #28462 ](https://github.com/oxc-project/oxc/pull/28462 ).
2026-10-30 21:16:18 +00:00
..
2026-04-08 17:33:19 +02:00
2026-01-05 07:55:47 -08:00
2025-10-14 10:14:59 -04:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2026-04-08 17:33:19 +02:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2026-04-08 17:33:19 +02:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2025-01-09 10:20:06 +01:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2026-04-08 17:33:19 +02:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2026-04-08 17:33:19 +02:00
2026-01-05 07:55:47 -08:00
2026-04-08 17:33:19 +02:00
2026-04-08 17:33:19 +02:00
2026-04-08 17:33:19 +02:00
2026-04-08 17:33:19 +02:00
2026-04-08 17:33:19 +02:00
2026-04-08 17:33:19 +02:00
2026-04-08 17:33:19 +02:00
2025-10-14 10:14:59 -04:00
2025-10-17 08:49:16 -04:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2025-10-14 10:14:59 -04:00
2026-01-05 07:55:47 -08:00
2026-04-08 17:33:19 +02:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2025-10-14 10:14:59 -04:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2025-05-22 07:52:21 +02:00
2026-01-05 07:55:47 -08:00
2025-10-14 10:14:59 -04:00
2025-01-09 10:20:06 +01:00
2025-10-14 10:14:59 -04:00
2026-04-08 17:33:19 +02:00
2025-10-14 10:14:59 -04:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2025-10-14 10:14:59 -04:00
2026-04-08 17:33:19 +02:00
2026-06-28 23:23:37 +01:00
2026-01-05 07:55:47 -08:00
2025-10-14 10:14:59 -04:00
2025-12-15 09:29:50 -06:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2025-10-14 10:14:59 -04:00
2026-01-05 07:55:47 -08:00
2025-12-12 12:02:25 -05:00
2026-06-28 23:23:37 +01:00
2025-10-14 10:14:59 -04:00
2026-01-05 07:55:47 -08:00
2026-04-08 17:33:19 +02:00
2025-10-14 10:14:59 -04:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2025-10-14 10:14:59 -04:00
2026-04-08 17:33:19 +02:00
2026-04-08 17:33:19 +02:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2025-10-14 10:14:59 -04:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2026-10-09 12:26:57 -04:00
2026-01-05 07:55:47 -08:00
2026-06-05 07:54:07 +01:00
2026-04-08 17:33:19 +02:00
2026-10-09 12:26:57 -04:00
2026-10-09 12:26:57 -04:00
2026-10-09 12:26:57 -04:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2026-10-09 12:26:57 -04:00
2026-10-09 12:26:57 -04:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2026-10-30 21:16:18 +00:00
2025-12-15 09:29:50 -06:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2025-05-30 15:00:56 -05:00
2026-01-05 07:55:47 -08:00
2026-10-09 12:26:57 -04:00
2025-12-15 09:29:50 -06:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2026-04-08 17:33:19 +02:00
2026-10-09 12:26:57 -04:00
2026-10-09 12:26:57 -04:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2025-07-27 12:41:03 +00:00
2026-10-09 12:26:57 -04:00
2025-07-27 12:41:03 +00:00
2026-05-26 13:54:41 -07:00
2026-05-16 16:32:57 +01:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2026-09-07 17:53:16 +02:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2025-12-15 09:29:50 -06:00
2026-01-05 07:55:47 -08:00
2026-10-09 12:26:57 -04:00
2026-01-05 07:55:47 -08:00
2026-06-28 23:23:37 +01:00
2026-01-05 07:55:47 -08:00
2025-11-18 10:48:14 -05:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2025-06-15 06:53:06 +01:00
2026-10-09 12:26:57 -04:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2026-10-09 12:26:57 -04:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2026-10-09 12:26:57 -04:00
2026-01-05 07:55:47 -08:00
2026-10-09 12:26:57 -04:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2025-11-18 12:02:09 -06:00
2026-01-05 07:55:47 -08:00
2025-11-18 12:02:09 -06:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2026-04-08 17:33:19 +02:00
2026-04-08 17:33:19 +02:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2025-11-17 07:30:34 -06:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2026-04-08 17:33:19 +02:00
2026-04-08 17:33:19 +02:00
2026-01-05 07:55:47 -08:00
2026-10-09 12:26:57 -04:00
2025-12-15 09:29:50 -06:00
2025-11-18 10:48:14 -05:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2025-05-22 07:52:21 +02:00
2025-05-22 07:52:21 +02:00
2026-10-09 12:26:57 -04:00
2026-10-09 12:26:57 -04:00
2026-01-05 07:55:47 -08:00
2025-10-27 09:52:17 -05:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2026-10-09 12:26:57 -04:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2026-04-08 17:33:19 +02:00
2026-10-09 12:26:57 -04:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2026-10-09 12:26:57 -04:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2026-10-09 12:26:57 -04:00
2026-04-08 17:33:19 +02:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2025-01-09 10:20:06 +01:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2026-06-28 23:23:37 +01:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2026-04-08 17:33:19 +02:00
2026-01-05 07:55:47 -08:00
2025-11-17 07:30:34 -06:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2026-04-08 17:33:19 +02:00
2026-01-05 07:55:47 -08:00
2026-04-08 17:33:19 +02:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2026-04-08 17:33:19 +02:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2026-06-28 23:23:37 +01:00
2026-07-01 23:23:21 +01:00
2026-07-01 23:23:21 +01:00
2025-11-17 07:30:34 -06:00
2026-03-31 18:48:24 +02:00
2026-03-31 18:48:24 +02:00
2026-10-09 12:26:57 -04:00
2026-10-09 12:26:57 -04:00
2026-01-05 07:55:47 -08:00
2026-04-08 17:33:19 +02:00
2026-01-05 07:55:47 -08:00
2026-01-05 07:55:47 -08:00
2026-04-08 17:33:19 +02:00
2026-10-09 12:26:57 -04:00
2025-06-07 16:02:43 +02:00
2026-10-09 12:26:57 -04:00
2026-01-05 07:55:47 -08:00