Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# **Upcoming release**

- #83 Report unknown source encodings as ModuleSyntaxError instead of leaking LookupError (@Aschenbath)

- #859 Fix `find_definition`/Rename not resolving `async def` methods called via `self` (@gadievron)
- #895 patchedast Starred and keyword now consumes their syntactically expected and ** (@lieryan)
- #896 patchedast cleanup and refactoring (@lieryan)
Expand Down
2 changes: 2 additions & 0 deletions rope/base/pyobjectsdef.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ def _init_source(self, pycore, source_code, resource):
raise exceptions.ModuleSyntaxError(filename, e.lineno, e.msg)
except UnicodeDecodeError as e:
raise exceptions.ModuleSyntaxError(filename, 1, "%s" % (e.reason))
except LookupError as e:
raise exceptions.ModuleSyntaxError(filename, 1, str(e)) from e
return source_code, ast_node

@utils.prevent_recursion(lambda: {})
Expand Down
4 changes: 4 additions & 0 deletions ropetest/contrib/codeassisttest.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ def _assist(self, code, offset=None, **args):
def test_simple_assist(self):
self._assist("", 0)

def test_unknown_source_encoding_reports_module_syntax_error(self):
with self.assertRaises(exceptions.ModuleSyntaxError):
self._assist("# coding: utf-8X\n", 0, maxfixes=5)

def assert_completion_in_result(self, name, scope, result, type=None):
for proposal in result:
if proposal.name == name:
Expand Down
7 changes: 7 additions & 0 deletions ropetest/pycoretest.py
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,13 @@ def test_syntax_errors_in_code(self):
with self.assertRaises(exceptions.ModuleSyntaxError):
libutils.get_string_module(self.project, "xyx print\n")

def test_unknown_source_encoding_is_a_module_syntax_error(self):
with self.assertRaises(exceptions.ModuleSyntaxError) as caught:
libutils.get_string_module(self.project, "# coding: utf-8X\n")
self.assertEqual(caught.exception.filename, "string")
self.assertEqual(caught.exception.lineno, 1)
self.assertIn("unknown encoding", str(caught.exception))

def test_holding_error_location_information(self):
try:
libutils.get_string_module(self.project, "xyx print\n")
Expand Down
Loading