# Buggy code
def parse_top_import(cls, results):
    """Splits the result of import_pattern into component strings.

    Examples:

    'from pkg import a,b,c' gives
    (('pkg', None), [('a', None), ('b', None), ('c', None)])

    'import pkg' gives
    (('pkg', None), [])

    'from pkg import a as b' gives
    (('pkg', None), [('a', 'b')])

    'import pkg as pkg2' gives
    (('pkg', 'pkg2'), [])

    Args:
      results: The values from import_pattern.

    Returns:
      A tuple of the package name and the list of imported names. Each name is a
      tuple of original name and alias.
    """

    pkg, names = results["pkg"], results.get("names", None)

    if len(pkg) == 1 and pkg[0].type == pygram.python_symbols.dotted_as_name:
        pkg_out = cls._parse_import_alias(list(pkg[0].leaves()))
    else:
        pkg_out = ("".join(map(str, pkg)).strip(), None)

    names_out = []
    if names:
        names = split_comma(names.leaves())
        for name in names:
            if len(name) == 1:
                assert name[0].type in (token.NAME, token.STAR)
                names_out.append((name[0].value, None))
            else:
                names_out.append(cls._parse_import_alias(name))

    return pkg_out, names_out


# Traceback (AssertionError)
$ cat import-bug.py
import collections.abc as abc
$ cat import-bug.pyi
import collections.abc as abc
$ pytype --version
2020.10.08
$ merge-pyi import-bug.py import-bug.pyi
Traceback (most recent call last):
File "/Users/shane/pymongo-pycharm-3.8/bin/merge-pyi", line 8, in <module>
sys.exit(main())
File "/Users/shane/pymongo-pycharm-3.8/lib/python3.8/site-packages/pytype/tools/merge_pyi/main.py", line 82, in main
annotated_src = merge_pyi.annotate_string(args, py_src, pyi_src)
File "/Users/shane/pymongo-pycharm-3.8/lib/python3.8/site-packages/pytype/tools/merge_pyi/merge_pyi.py", line 936, in annotate_string
parsed_pyi = Pyi.parse(pyi_src)
File "/Users/shane/pymongo-pycharm-3.8/lib/python3.8/site-packages/pytype/tools/merge_pyi/merge_pyi.py", line 763, in parse
pkg, names = cls.parse_top_import(match_results)
File "/Users/shane/pymongo-pycharm-3.8/lib/python3.8/site-packages/pytype/tools/merge_pyi/merge_pyi.py", line 834, in parse_top_import
pkg_out = cls._parse_import_alias(list(pkg[0].leaves()))
File "/Users/shane/pymongo-pycharm-3.8/lib/python3.8/site-packages/pytype/tools/merge_pyi/merge_pyi.py", line 801, in _parse_import_alias
assert [leaf.type for leaf in leaves] == [token.NAME] * 3
AssertionError

# Fixed code
def parse_top_import(cls, results):
    """Splits the result of import_pattern into component strings.

    Examples:

    'from pkg import a,b,c' gives
    (('pkg', None), [('a', None), ('b', None), ('c', None)])

    'import pkg' gives
    (('pkg', None), [])

    'from pkg import a as b' gives
    (('pkg', None), [('a', 'b')])

    'import pkg as pkg2' gives
    (('pkg', 'pkg2'), [])

    'import pkg.a as b' gives
    (('pkg.a', 'b'), [])

    Args:
      results: The values from import_pattern.

    Returns:
      A tuple of the package name and the list of imported names. Each name is a
      tuple of original name and alias.
    """

    pkg, names = results["pkg"], results.get("names", None)

    if len(pkg) == 1 and pkg[0].type == pygram.python_symbols.dotted_as_name:
        pkg_out = cls._parse_import_alias(list(pkg[0].leaves()))
    else:
        pkg_out = ("".join(map(str, pkg)).strip(), None)

    names_out = []
    if names:
        names = split_comma(names.leaves())
        for name in names:
            if len(name) == 1:
                assert name[0].type in (token.NAME, token.STAR)
                names_out.append((name[0].value, None))
            else:
                names_out.append(cls._parse_import_alias(name))

    return pkg_out, names_out