Skip to content

Confusing error string on typo'd module import #5631

@leogott

Description

@leogott

Summary

When attempting to import a module, and (misremembering or mistyping) the module name to include a dash - character, rustpython will give a (true but) misleading error message.

This is mostly a problem in the online demo or running a script, as the REPL at least points out the exact location of the error.

Expected

>>> import py-compile
             ^
SyntaxError: import name contains invalid character `-`

Actual

>>>>> import aa-bb
  File "<stdin>", line 1
    import aa-bb
             ^
SyntaxError: simple statements must be separated by newlines or semicolons

Python Documentation

Python 3.13.2 | packaged by conda-forge | (main, Feb 17 2025, 14:10:22) [GCC 13.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import aa-bb
  File "<python-input-0>", line 1
    import aa-bb
             ^
SyntaxError: invalid syntax

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions