[Python-ideas] allow `lambda' to be spelled λ

Steven D'Aprano steve at pearwood.info
Thu Jul 21 11:45:43 EDT 2016

On Wed, Jul 20, 2016 at 11:26:58PM -0700, Rustom Mody wrote:

> >>> А = 1
> >>> A = A + 1
> because the A's look more indistinguishable than the sigmas and are 
> internally more distinct
>  If the choice is to simply disallow the confusables that’s probably the 
> best choice
> 1. Disallow co-existence of confusables (in identifiers)

That would require disallowing 1 l and I, as well as O and 0. Or are 
you, after telling us off for taking an ASCII-centric perspective, going 
to exempt ASCII confusables?

In a dynamic language like Python, how do you prohibit these 
confusables? Every time Python does a name binding operation, is it 
supposed to search the entire namespace for potential confusables? 
That's going to be awful expensive.

Confusables are a real problem in URLs, because they can be used for 
phishing attacks. While even the most tech-savvy user is vulnerable, it 
is especially the *least* savvy users who are at risk, which makes it 
all the more important to protect against confusables in URLs.

But in programming code? Your demonstration with the Latin A and the 
Greek alpha Α or Cyrillic А is just a party trick. In a world where most 
developers do something like:

pip install randompackage
python -m randompackage

without ever once looking at the source code, I think we have bigger 
problems. Or rather, even the bigger problems are not that big.

If you're worried about confusables, there are alternatives other than 
banning them: your editor or linter might highlight them. Or rather than 
syntax highlighting, perhaps editors should use *semantic highlighting* 
and colour-code variables:


in which case your A and A will be highlighted in completely different 
colours, completely ruining the trick.

(Aside: this may also help with the "oops I misspelled my variable and 
the compiler didn't complain" problem. If "self.dashes" is green and 
"self.dahses" is blue, you're more likely to notice the typo.) 


More information about the Python-ideas mailing list