This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Print a useful error message when trying to import modules with dots or dashes
ClosedPublic

Authored by JDevlieghere on Feb 16 2021, 7:10 PM.

Details

Summary

LLDB does not like to import Python files with dashes or dots in their name. While the former are technically allowed, they're discouraged [1]. Dots are allowed for subpackages but not in module names. This patch improves the user experience by printing a useful error.

Currently lldb prints:

error: module importing failed: SyntaxError('invalid syntax', ('<string>', 1, 11, 'import foo-bar\n'))

After this patch:

error: module importing failed: Python discourages dashes in module names: foo-bar

rdar://74263511

Diff Detail

Event Timeline

JDevlieghere requested review of this revision.Feb 16 2021, 7:10 PM
JDevlieghere updated this revision to Diff 324169.
JDevlieghere created this revision.
JDevlieghere edited the summary of this revision. (Show Details)

module specification -> module names

JDevlieghere edited the summary of this revision. (Show Details)Feb 16 2021, 7:12 PM
JDevlieghere added a comment.EditedFeb 16 2021, 7:17 PM

FWIW I played around with __import__ and importlib.import_module which does allow you to import modules with dashes, but unlike import it doesn't add them to the globals. I'm sure there's a way around that, but it didn't seem worth the additional complexity.

mib accepted this revision.Feb 17 2021, 8:14 AM

LGTM!

This revision is now accepted and ready to land.Feb 17 2021, 8:14 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 17 2021, 10:00 AM