# Buggy code
def Find(name):
    f = None
    if name.startswith("__builtin__"):
        if name == "__builtin__.str":
            name = "org.python.core.PyString"
        elif name == "__builtin__.dict":
            name = "org.python.core.PyDictionary"

    mod = _imp(name)
    parent = mod
    foundAs = ""

    if hasattr(mod, "__file__"):
        f = mod.__file__

    components = name.split(".")
    old_comp = None
    for comp in components[1:]:
        try:
            # this happens in the following case:
            # we have mx.DateTime.mxDateTime.mxDateTime.pyd
            # but after importing it, mx.DateTime.mxDateTime does shadows access to mxDateTime.pyd
            mod = getattr(mod, comp)
        except AttributeError:
            if old_comp != comp:
                raise

        if hasattr(mod, "__file__"):
            f = mod.__file__
        else:
            if len(foundAs) > 0:
                foundAs = foundAs + "."
            foundAs = foundAs + comp

        old_comp = comp

    if f is None and name.startswith("java.lang"):
        # Hack: java.lang.__file__ is None on Jython 2.7 (whereas it pointed to rt.jar on Jython 2.5).
        f = _java_rt_file

    if f is not None:
        if f.endswith(".pyc"):
            f = f[:-1]
        elif f.endswith("$py.class"):
            f = f[: -len("$py.class")] + ".py"
    return f, mod, parent, foundAs


# Traceback (AttributeError)
/usr/bin/env /usr/bin/python3 /Users/jeffery/.vscode/extensions/ms-python.python-2020.11.371526539/pythonFiles/lib/python/debugpy/launcher 60731 -- odoo-bin -c odoo.conf
~/git-repo/odoo(master ✗)  /usr/bin/env /usr/bin/python3 /Users/jeffery/.vscode/extensions/ms-python.python-2020.11.371526539/pythonFiles/lib/python/debugpy/launcher 60731 -- odoo-bin -c odoo.conf
Traceback (most recent call last):
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/Users/jeffery/.vscode/extensions/ms-python.python-2020.11.371526539/pythonFiles/lib/python/debugpy/__main__.py", line 43, in <module>
from debugpy.server import cli
File "/Users/jeffery/.vscode/extensions/ms-python.python-2020.11.371526539/pythonFiles/lib/python/debugpy/../debugpy/server/__init__.py", line 9, in <module>
import debugpy._vendored.force_pydevd  # noqa
File "/Users/jeffery/.vscode/extensions/ms-python.python-2020.11.371526539/pythonFiles/lib/python/debugpy/../debugpy/_vendored/force_pydevd.py", line 15, in <module>
prefix_matcher('pydev', '_pydev'))
File "/Users/jeffery/.vscode/extensions/ms-python.python-2020.11.371526539/pythonFiles/lib/python/debugpy/../debugpy/_vendored/__init__.py", line 106, in check_modules
elif not mod.__file__.startswith(root):
AttributeError: 'NoneType' object has no attribute 'startswith'

# Fixed code
def Find(name):
    f = None
    if name.startswith("__builtin__"):
        if name == "__builtin__.str":
            name = "org.python.core.PyString"
        elif name == "__builtin__.dict":
            name = "org.python.core.PyDictionary"

    mod = _imp(name)
    parent = mod
    foundAs = ""

    try:
        f = getattr(mod, "__file__", None)
    except:
        f = None

    components = name.split(".")
    old_comp = None
    for comp in components[1:]:
        try:
            # this happens in the following case:
            # we have mx.DateTime.mxDateTime.mxDateTime.pyd
            # but after importing it, mx.DateTime.mxDateTime does shadows access to mxDateTime.pyd
            mod = getattr(mod, comp)
        except AttributeError:
            if old_comp != comp:
                raise

        if hasattr(mod, "__file__"):
            f = mod.__file__
        else:
            if len(foundAs) > 0:
                foundAs = foundAs + "."
            foundAs = foundAs + comp

        old_comp = comp

    if f is None and name.startswith("java.lang"):
        # Hack: java.lang.__file__ is None on Jython 2.7 (whereas it pointed to rt.jar on Jython 2.5).
        f = _java_rt_file

    if f is not None:
        if f.endswith(".pyc"):
            f = f[:-1]
        elif f.endswith("$py.class"):
            f = f[: -len("$py.class")] + ".py"
    return f, mod, parent, foundAs