← Back to context

Comment by llimllib

5 hours ago

3.15: https://docs.python.org/3.15/whatsnew/3.15.html#whatsnew315-...

> When an AttributeError on a builtin type has no close match via Levenshtein distance, the error message now checks a static table of common method names from other languages (JavaScript, Java, Ruby, C#) and suggests the Python equivalent

Oh, that is such a nice thing.

  • It's unrelated to the lazy keyword. Instead it's another feature related to error messages.

    The example:

      >> 'hello'.toUpperCase()
      Traceback (most recent call last):
      ...
      AttributeError: 'str' object has no attribute 'toUpperCase'. Did you mean '.upper'?

    • In the Rust toolchain we've done the same. It just so happens that rustdoc already has introduced annotations for "aliases" so that when someone searches for push and it doesn't exist, append would show up. Having those annotations already meant that bootstrapping the feature to check the aliases during name resolution errors in rustc was almost trivial. I love it when improving one thing improves another indirectly too.

      I really appreciate them going out of their way to do this, being quite aware of the hidden complexity in doing it.

    • I’ve often thought it would be funny if instead of an error message for stuff like this, a language could be designed to be “typo-insensitive”. If a method or function call is similar enough to an existing one or a common one from other languages, to just have it silently use that.

      2 replies →

  • Now I'm wishing for a single cross-language library, that I can somehow inject into every compiler/runtime/checker to get this, but with a single source of truth and across a wide range of languages. I hit this damn issue all the time, writing code in one language for another, would truly be a bliss to have that problem solved once and for all.

    • If you had a "canonical datastructure database", you could have very short annotations on every standard library for any language that indexes a function to their canonical name. After that you only need to update the database.