
On 1/24/22 2:06 AM, akuviljanen17@gmail.com wrote:
What exactly is wrong with SafeStr or SafeString? The whole goal is to distinguish between arbitrary user input and strings that are known to be safe, so to me, SafeStr and SafeString are the only suggestions so far that make sense.
There are other kinds of checks spellable by Python's typing system that could result in a "safe str". Therefore using the term SafeStr here to mean a very specific type of "safe str" - specifically a constant expression - seems misleading to me. As an example of another type of "safe str", consider the following code: Url = NewType('Url', str) def parse_url(s: str) -> Url|None: if ...: return cast(Url, s) else: return None def is_url(s: str) -> TypeGuard[Url]: if ...: return True else: return False Here, "Url" would be a kind of "safe str" type because you could only generate it through a parsing function. In particular a `str` will not implicitly convert to an `Url` because it is using a NewType. -- David Foster | Seattle, WA, USA Contributor to TypedDict support for mypy