Skip to content

gh-131798: Narrow the return type of _FORMAT_SIMPLE and _FORMAT_WITH_SPEC to str#146639

Open
NekoAsakura wants to merge 1 commit intopython:mainfrom
NekoAsakura:format-type-narrowing
Open

gh-131798: Narrow the return type of _FORMAT_SIMPLE and _FORMAT_WITH_SPEC to str#146639
NekoAsakura wants to merge 1 commit intopython:mainfrom
NekoAsakura:format-type-narrowing

Conversation

@NekoAsakura
Copy link
Copy Markdown
Contributor

@NekoAsakura NekoAsakura commented Mar 30, 2026

res = sym_new_type(ctx, &PyUnicode_Type);
}

op(_FORMAT_WITH_SPEC, (value, fmt_spec -- res)) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can return a subclass, e.g.

class my(str):
    def __format__(self, spec):
        return self
m=my('aap')
type(f'{m}')

Does the sym_new_type(ctx, &PyUnicode_Type); not guarantee we have an exact type?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants