-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Preserve str subclasses in ascii() for ASCII-only __repr__ results
#7455
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -5,3 +5,23 @@ | |||||||
| assert ascii(chr(0x10001)) == "'\\U00010001'" | ||||||||
| assert ascii(chr(0x9999)) == "'\\u9999'" | ||||||||
| assert ascii(chr(0x0A)) == "'\\n'" | ||||||||
|
|
||||||||
|
|
||||||||
| class MyStr(str): | ||||||||
| pass | ||||||||
|
|
||||||||
|
|
||||||||
| class Foo: | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [auto-format] reported by reviewdog 🐶
Suggested change
|
||||||||
| def __repr__(self): | ||||||||
| return MyStr("hello") | ||||||||
|
|
||||||||
|
|
||||||||
| class Bar: | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [auto-format] reported by reviewdog 🐶
Suggested change
|
||||||||
| def __repr__(self): | ||||||||
| return MyStr("héllo") | ||||||||
|
|
||||||||
|
|
||||||||
| assert type(ascii(Foo())) is MyStr | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [auto-format] reported by reviewdog 🐶
Suggested change
|
||||||||
| assert ascii(Foo()) == MyStr("hello") | ||||||||
| assert type(ascii(Bar())) is str | ||||||||
| assert ascii(Bar()) == "h\\xe9llo" | ||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[auto-format] reported by reviewdog 🐶