diff --git a/retype.py b/retype.py
index eee4b8e..d59e1b0 100644
--- a/retype.py
+++ b/retype.py
@@ -12,6 +12,7 @@ from pathlib import Path
 import re
 import sys
 import threading
+import tokenize
 import traceback
 
 import click
@@ -138,9 +139,9 @@ def retype_file(src, pyi_dir, targets, *, quiet=False, hg=False):
 
     Type comments in sources are normalized to type annotations.
     """
-    with open(src) as src_file:
-        src_txt = src_file.read()
-    src_node = lib2to3_parse(src_txt)
+    with tokenize.open(src) as src_buffer:
+        src_encoding = src_buffer.encoding
+        src_node = lib2to3_parse(src_buffer.read())
     try:
         with open((pyi_dir / src.name).with_suffix('.pyi')) as pyi_file:
             pyi_txt = pyi_file.read()
@@ -156,7 +157,7 @@ def retype_file(src, pyi_dir, targets, *, quiet=False, hg=False):
         reapply_all(pyi_ast.body, src_node)
     fix_remaining_type_comments(src_node)
     targets.mkdir(parents=True, exist_ok=True)
-    with open(targets / src.name, 'w') as target_file:
+    with open(targets / src.name, 'w', encoding=src_encoding) as target_file:
         target_file.write(lib2to3_unparse(src_node, hg=hg))
     return targets / src.name
 
@@ -169,7 +170,11 @@ def lib2to3_parse(src_txt):
         result = drv.parse_string(src_txt, True)
     except ParseError as pe:
         lineno, column = pe.context[1]
-        faulty_line = src_txt.splitlines()[lineno - 1]
+        lines = src_txt.splitlines()
+        if src_txt[-1] != '\n':
+            faulty_line = "The source is missing a trailing newline."
+        else:
+            faulty_line = lines[lineno - 1]
         raise ValueError(f"Cannot parse: {lineno}:{column}: {faulty_line}") from None
 
     if isinstance(result, Leaf):

diff --git a/tests/test_retype.py b/tests/test_retype.py
index 5142782..dfb4d99 100644
--- a/tests/test_retype.py
+++ b/tests/test_retype.py
@@ -2134,6 +2134,17 @@ class PrintStmtTestCase(RetypeTestCase):
             str(exception),
         )
 
+class ParseErrorTestCase(RetypeTestCase):
+    def test_missing_trailing_newline_crash(self) -> None:
+        pyi_txt = "def f() -> None: ...\n"
+        src_txt = """
+        def f():
+            pass"""
+        exception = self.assertReapplyRaises(pyi_txt, src_txt, ValueError)
+        self.assertEqual(
+            'Cannot parse: 4:0: The source is missing a trailing newline.',
+            str(exception),
+        )
 
 class PostProcessTestCase(RetypeTestCase):
     def test_straddling_variable_comments(self) -> None:

lib2to3_parse assumes that the ParseError will always refer to an existing line
There seems to be a case where `ParseError` will report the line number after the last line number, causing an `IndexError` in retype:

Example file (core.py):
```
def get_message():
    return '123'
```

Example stub (types/core.pyi):
```
def get_message() -> str: ...
```

```
$>retype --traceback core.py
error: core.py: list index out of range
Traceback (most recent call last):
  File "retype.py", line 110, in retype_path
    retype_file(src, pyi_dir, targets, quiet=quiet, hg=hg)
  File "retype.py", line 132, in retype_file
    src_node = lib2to3_parse(src_txt)
  File "retype.py", line 161, in lib2to3_parse
    faulty_line = src_txt.splitlines()[lineno - 1]
IndexError: list index out of range
```

I haven't gone digging yet to see why the `Driver` is failing to parse this, but it seems that this should be fixed as well.

**Tested using:** 
- `Python 3.6.1 (v3.6.1:69c0db5, Mar 21 2017, 17:54:52) [MSC v.1900 32 bit (Intel)] on win32`
- `Python 3.6.1 (default, May 11 2017, 22:14:44) [GCC 4.9.2] on linux`

tests/test_retype.py::ParseErrorTestCase::test_missing_trailing_newline_crash
tests/test_retype.py::ImportTestCase::test_equal tests/test_retype.py::ImportTestCase::test_matched1 tests/test_retype.py::ImportTestCase::test_matched2 tests/test_retype.py::ImportTestCase::test_matched3 tests/test_retype.py::ImportTestCase::test_src_empty tests/test_retype.py::ImportTestCase::test_unmatched1 tests/test_retype.py::ImportTestCase::test_unmatched2 tests/test_retype.py::ImportTestCase::test_unmatched3 tests/test_retype.py::ImportTestCase::test_unmatched4 tests/test_retype.py::ImportTestCase::test_unmatched5 tests/test_retype.py::ImportTestCase::test_unmatched6 tests/test_retype.py::ImportTestCase::test_unmatched7 tests/test_retype.py::FromImportTestCase::test_equal tests/test_retype.py::FromImportTestCase::test_matched1 tests/test_retype.py::FromImportTestCase::test_matched2 tests/test_retype.py::FromImportTestCase::test_matched3 tests/test_retype.py::FromImportTestCase::test_src_empty tests/test_retype.py::FromImportTestCase::test_unmatched1 tests/test_retype.py::FromImportTestCase::test_unmatched2 tests/test_retype.py::FromImportTestCase::test_unmatched3 tests/test_retype.py::FromImportTestCase::test_unmatched4 tests/test_retype.py::FromImportTestCase::test_unmatched5 tests/test_retype.py::FromImportTestCase::test_unmatched6 tests/test_retype.py::FromImportTestCase::test_unmatched7 tests/test_retype.py::FromImportTestCase::test_unmatched8 tests/test_retype.py::FunctionReturnTestCase::test_complex_return_value tests/test_retype.py::FunctionReturnTestCase::test_complex_return_value2 tests/test_retype.py::FunctionReturnTestCase::test_complex_return_value3 tests/test_retype.py::FunctionReturnTestCase::test_complex_return_value_spurious_type_comment tests/test_retype.py::FunctionReturnTestCase::test_complex_return_value_type_comment tests/test_retype.py::FunctionReturnTestCase::test_mismatched_return_value tests/test_retype.py::FunctionReturnTestCase::test_missing_return_value_both tests/test_retype.py::FunctionReturnTestCase::test_missing_return_value_both_incremental tests/test_retype.py::FunctionReturnTestCase::test_missing_return_value_pyi tests/test_retype.py::FunctionReturnTestCase::test_missing_return_value_pyi_incremental tests/test_retype.py::FunctionReturnTestCase::test_missing_return_value_src tests/test_retype.py::FunctionReturnTestCase::test_missing_return_value_src_incremental tests/test_retype.py::FunctionArgumentTestCase::test_complex_ann tests/test_retype.py::FunctionArgumentTestCase::test_complex_ann_with_default tests/test_retype.py::FunctionArgumentTestCase::test_complex_sig1 tests/test_retype.py::FunctionArgumentTestCase::test_complex_sig1_type_comment tests/test_retype.py::FunctionArgumentTestCase::test_complex_sig2 tests/test_retype.py::FunctionArgumentTestCase::test_complex_sig2_type_comment tests/test_retype.py::FunctionArgumentTestCase::test_complex_sig3_type_comment tests/test_retype.py::FunctionArgumentTestCase::test_complex_sig4_spurious_type_comment tests/test_retype.py::FunctionArgumentTestCase::test_complex_sig4_type_comment tests/test_retype.py::FunctionArgumentTestCase::test_complex_sig_async tests/test_retype.py::FunctionArgumentTestCase::test_extra_arg1 tests/test_retype.py::FunctionArgumentTestCase::test_extra_arg2 tests/test_retype.py::FunctionArgumentTestCase::test_extra_arg_kwonly tests/test_retype.py::FunctionArgumentTestCase::test_missing_ann_both tests/test_retype.py::FunctionArgumentTestCase::test_missing_ann_both_incremental tests/test_retype.py::FunctionArgumentTestCase::test_missing_ann_both_multiple_args_incremental tests/test_retype.py::FunctionArgumentTestCase::test_missing_ann_pyi tests/test_retype.py::FunctionArgumentTestCase::test_missing_ann_src tests/test_retype.py::FunctionArgumentTestCase::test_missing_arg tests/test_retype.py::FunctionArgumentTestCase::test_missing_arg2 tests/test_retype.py::FunctionArgumentTestCase::test_missing_arg_kwonly tests/test_retype.py::FunctionArgumentTestCase::test_missing_default_arg_pyi tests/test_retype.py::FunctionArgumentTestCase::test_missing_default_arg_src tests/test_retype.py::FunctionArgumentTestCase::test_no_args tests/test_retype.py::FunctionVariableTestCase::test_basic tests/test_retype.py::FunctionVariableTestCase::test_complex tests/test_retype.py::FunctionVariableTestCase::test_complex_type tests/test_retype.py::FunctionVariableTestCase::test_default_type tests/test_retype.py::FunctionVariableTestCase::test_no_value tests/test_retype.py::FunctionVariableTestCase::test_type_mismatch tests/test_retype.py::FunctionVariableTypeCommentTestCase::test_basic tests/test_retype.py::FunctionVariableTypeCommentTestCase::test_complex tests/test_retype.py::FunctionVariableTypeCommentTestCase::test_complex_type tests/test_retype.py::FunctionVariableTypeCommentTestCase::test_default_type tests/test_retype.py::FunctionVariableTypeCommentTestCase::test_no_value tests/test_retype.py::FunctionVariableTypeCommentTestCase::test_no_value_type_comment tests/test_retype.py::FunctionVariableTypeCommentTestCase::test_type_mismatch tests/test_retype.py::MethodTestCase::test_basic tests/test_retype.py::MethodTestCase::test_complex_sig1_type_comment tests/test_retype.py::MethodTestCase::test_complex_sig2_type_comment tests/test_retype.py::MethodTestCase::test_complex_sig3_type_comment tests/test_retype.py::MethodTestCase::test_complex_sig4_type_comment tests/test_retype.py::MethodTestCase::test_complex_sig5_type_comment tests/test_retype.py::MethodTestCase::test_decorator_mismatch tests/test_retype.py::MethodTestCase::test_decorator_mismatch2 tests/test_retype.py::MethodTestCase::test_decorator_mismatch3 tests/test_retype.py::MethodTestCase::test_function tests/test_retype.py::MethodTestCase::test_missing_class tests/test_retype.py::MethodTestCase::test_staticmethod tests/test_retype.py::MethodTestCase::test_two_classes tests/test_retype.py::MethodVariableTestCase::test_basic tests/test_retype.py::MethodVariableTestCase::test_complex tests/test_retype.py::MethodVariableTestCase::test_default_type tests/test_retype.py::MethodVariableTestCase::test_no_value tests/test_retype.py::MethodVariableTestCase::test_type_mismatch tests/test_retype.py::MethodVariableTypeCommentTestCase::test_basic tests/test_retype.py::MethodVariableTypeCommentTestCase::test_complex tests/test_retype.py::MethodVariableTypeCommentTestCase::test_default_type tests/test_retype.py::MethodVariableTypeCommentTestCase::test_no_value tests/test_retype.py::MethodVariableTypeCommentTestCase::test_no_value_type_comment tests/test_retype.py::MethodVariableTypeCommentTestCase::test_type_mismatch tests/test_retype.py::ModuleLevelVariableTestCase::test_alias_basic tests/test_retype.py::ModuleLevelVariableTestCase::test_alias_many tests/test_retype.py::ModuleLevelVariableTestCase::test_alias_typevar tests/test_retype.py::ModuleLevelVariableTestCase::test_alias_typevar_typing tests/test_retype.py::ModuleLevelVariableTestCase::test_basic tests/test_retype.py::ModuleLevelVariableTestCase::test_complex tests/test_retype.py::ModuleLevelVariableTestCase::test_complex_with_imports tests/test_retype.py::ModuleLevelVariableTestCase::test_default_type tests/test_retype.py::ModuleLevelVariableTestCase::test_no_value tests/test_retype.py::ModuleLevelVariableTestCase::test_type_mismatch tests/test_retype.py::ClassVariableTestCase::test_basic tests/test_retype.py::ClassVariableTestCase::test_complex tests/test_retype.py::ClassVariableTestCase::test_default_type tests/test_retype.py::ClassVariableTestCase::test_instance_fields_assignment_docstring tests/test_retype.py::ClassVariableTestCase::test_instance_fields_assignment_no_docstring tests/test_retype.py::ClassVariableTestCase::test_instance_fields_no_assignment tests/test_retype.py::ClassVariableTestCase::test_instance_fields_no_assignment_docstring tests/test_retype.py::ClassVariableTestCase::test_instance_fields_no_assignment_no_docstring tests/test_retype.py::ClassVariableTestCase::test_no_value tests/test_retype.py::ClassVariableTestCase::test_type_mismatch tests/test_retype.py::SerializeTestCase::test_serialize_attribute tests/test_retype.py::SerializeTestCase::test_serialize_name tests/test_retype.py::PrintStmtTestCase::test_print_stmt_crash tests/test_retype.py::PostProcessTestCase::test_straddling_function_signature_type_comments1 tests/test_retype.py::PostProcessTestCase::test_straddling_function_signature_type_comments2 tests/test_retype.py::PostProcessTestCase::test_straddling_function_signature_type_comments3 tests/test_retype.py::PostProcessTestCase::test_straddling_variable_comments