# Buggy code
def find_plugins(path, ptype):
    display.vvvv("Searching %s for plugins" % path)

    plugin_list = set()

    if not os.path.exists(path):
        display.vvvv("%s does not exist" % path)
        return plugin_list

    bkey = ptype.upper()
    for plugin in os.listdir(path):
        display.vvvv("Found %s" % plugin)
        full_path = "/".join([path, plugin])

        if plugin.startswith("."):
            continue
        elif os.path.isdir(full_path):
            continue
        elif any(plugin.endswith(x) for x in C.BLACKLIST_EXTS):
            continue
        elif plugin.startswith("__"):
            continue
        elif plugin in C.IGNORE_FILES:
            continue
        elif plugin.startswith("_"):
            if os.path.islink(full_path):  # avoids aliases
                continue

        plugin = os.path.splitext(plugin)[0]  # removes the extension
        plugin = plugin.lstrip("_")  # remove underscore from deprecated plugins

        if plugin not in BLACKLIST.get(bkey, ()):
            plugin_list.add(plugin)
            display.vvvv("Added %s" % plugin)

    return plugin_list


# Traceback (TypeError)
### on stable-2.7 branch

$ ansible-doc -a -vvv
ansible-doc 2.7.7.post0 (stable-2.7 bedfa3f3ff) last updated 2019/02/11 19:35:38 (GMT +550)
config file = None
configured module search path = [u'/home/akhisti/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /home/akhisti/work/myspace/ansible/lib/ansible
executable location = /home/akhisti/work/myspace/ansible/bin/ansible-doc
python version = 2.7.15 (default, Oct 15 2018, 15:26:09) [GCC 8.2.1 20180801 (Red Hat 8.2.1-2)]
No config file found; using defaults
ERROR! Unexpected Exception, this is probably a bug: get_all_plugins_of_type() takes exactly 2 arguments (3 given)
the full traceback was:

Traceback (most recent call last):
File "/home/akhisti/work/myspace/ansible/bin/ansible-doc", line 118, in <module>
exit_code = cli.run()
File "/home/akhisti/work/myspace/ansible/lib/ansible/cli/doc.py", line 120, in run
self.args = self.get_all_plugins_of_type(plugin_type, loader)
TypeError: get_all_plugins_of_type() takes exactly 2 arguments (3 given)



### on devel branch

$ ansible-doc --all
ERROR! Unexpected Exception, this is probably a bug: Values instance has no attribute '__getitem__'
the full traceback was:

Traceback (most recent call last):
File "/home/akhisti/work/myspace/ansible/bin/ansible-doc", line 110, in <module>
exit_code = cli.run()
File "/home/akhisti/work/myspace/ansible/lib/ansible/cli/doc.py", line 91, in run
super(DocCLI, self).run()
File "/home/akhisti/work/myspace/ansible/lib/ansible/cli/__init__.py", line 101, in run
self.parse()
File "/home/akhisti/work/myspace/ansible/lib/ansible/cli/__init__.py", line 422, in parse
options, args = self.post_process_args(options, args)
File "/home/akhisti/work/myspace/ansible/lib/ansible/cli/doc.py", line 83, in post_process_args
args = self.get_all_plugins_of_type(options['type'])
AttributeError: Values instance has no attribute '__getitem__'

# Fixed code
def find_plugins(path, ptype):
    display.vvvv("Searching %s for plugins" % path)

    plugin_list = set()

    if not os.path.exists(path):
        display.vvvv("%s does not exist" % path)
        return plugin_list

    if not os.path.isdir(path):
        display.vvvv("%s is not a directory" % path)
        return plugin_list

    bkey = ptype.upper()
    for plugin in os.listdir(path):
        display.vvvv("Found %s" % plugin)
        full_path = "/".join([path, plugin])

        if plugin.startswith("."):
            continue
        elif os.path.isdir(full_path):
            continue
        elif any(plugin.endswith(x) for x in C.BLACKLIST_EXTS):
            continue
        elif plugin.startswith("__"):
            continue
        elif plugin in C.IGNORE_FILES:
            continue
        elif plugin.startswith("_"):
            if os.path.islink(full_path):  # avoids aliases
                continue

        plugin = os.path.splitext(plugin)[0]  # removes the extension
        plugin = plugin.lstrip("_")  # remove underscore from deprecated plugins

        if plugin not in BLACKLIST.get(bkey, ()):
            plugin_list.add(plugin)
            display.vvvv("Added %s" % plugin)

    return plugin_list