Skip to content

fix: extend action should spread a scalar string by code point - #190

Closed
spokodev wants to merge 1 commit into
nodeca:masterfrom
spokodev:fix/extend-spreads-scalar-string
Closed

spokodev wants to merge 1 commit into
nodeca:masterfrom
spokodev:fix/extend-spreads-scalar-string

Conversation

@spokodev

@spokodev spokodev commented Sep 3, 2026

Copy link
Copy Markdown

action: 'extend' without nargs receives a single string value. Python's extend runs list.extend(values), and list.extend on a str iterates it by code point, so --foo abc produces ['a', 'b', 'c']. This port concatenates the string as a single element instead, producing ['abc'] — a silent divergence from the CPython 3.14.6 behaviour it targets (and not one of the intentional differences in doc/port_difference.md).

Spreading with Array.from when the value is a string matches Python's per-code-point iteration, including astral characters: --foo a😀b → ['a', '😀', 'b'], exactly as CPython 3.14.6 produces.

@puzrin puzrin closed this in 042e2c7 Sep 10, 2026
@puzrin

puzrin commented Sep 10, 2026

Copy link
Copy Markdown
Member

Fixed it different way, more close to python - for any iterable. There can be generator too:

parser.add_argument('--foo', {
    action: 'extend',
    type: function* (s) {
        yield* s.split(',')
    }
})
// --foo a,b → ['a', 'b']

Test removed as "not maintainable". Original tests are ports of mainstream.

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