-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Description
Summary of issue:
#5913 introduces a keyword operator for an unsafe conversion, and suggests spelling it as unsafe as
(two keywords in sequence). When #845 considered the same question, the suggestion was instead to spell this kind of keyword-with-modifier as a single keyword, such as unsafe_as
or assume_as
or try_as
.
Which approach do we prefer?
Details:
The simplest options here seem to be either:
- Always use compound keywords:
unsafe_as
,try_as
. This is simple and uninventive, and seems like the most conventional option. However, it's inflexible: what if we need anunsafe_try_as
? - Always use modifier keywords:
unsafe as
,try as
. This offers more flexibility, and is consistent with our approach to modifier keywords on declaration introducers. But it's somewhat novel and potentially surprising. There is prior art in Python'snot in
operator.
A third option to consider would be to say that it's unsafe
that's special, not operator modifiers, and that we want a single unsafe
keyword that's used consistently in all unsafe constructs for easy auditability. For example, we could eventually have: as
, unsafe as
, try_as
, unsafe try_as
.
Any other information that you want to share?
Multi-keyword operators would presumably allow arbitrary amounts of whitespace, including line breaks and line comments between the operators, which may be surprising but could be mitigated by making the formatter always keep them together on a line. There's also a possibility that multi-keyword operators may be harder to read, due to the possibility of misparsing them as (x unsafe) as y
, but I'm not aware of that being a problem for python's a not in b
, which could be misinterpreted as the valid-but-meaningless as a in not b
.