-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Char type as a special length one string type #4334
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
Comments
I think this is similar (in challenges and special-casing) to having a singleton type. (Imagine unary alphabet; for most purposes mypy doesn't know it's not). But it's less general and requires understanding of |
I've sometimes wondered about having a character type, but haven't yet found very convincing use cases. One option would be to implement this as a separate string-like type with a promotion from However, there are probably simpler ways to catch accidentally using |
|
There is also a common misconception about what a character is. There are code points and graphemes. What one sees in a text editor, are graphemes, what a computer sees in a file, are code points. Some graphemes are made of two code points, a code point for a base glyph and a code point for an overlayed glyph. As far I experienced it, Python deals with code point, so a grapheme made of two glyphs, will be a string of length 2. The best to deal with code points individually, is to deal with their integer value which can be retrieve with the I would rather say the issue is that Python does not provide a built-in iterator to iterate over a string as a sequence of code point integer values, but one can define such an iterator easily. I also believe there is no Python function to split a string into graphemes, by the way (unless i’m wrong). |
Cross post from typing repo: python/typing#510
The original issue contains some additional context, but is it feasible to implement a
Char
type as a special case ofText
type?The text was updated successfully, but these errors were encountered: