Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

False Positive In String Formatter #183

Closed
jbylund opened this issue Jan 17, 2020 · 1 comment
Closed

False Positive In String Formatter #183

jbylund opened this issue Jan 17, 2020 · 1 comment

Comments

@jbylund
Copy link
Contributor

jbylund commented Jan 17, 2020

Running vulture over

from string import Formatter

class StrictFormatter(Formatter):
    def check_unused_args(self, used_args, _args, kwargs):
        """Raise exception if any keyword arguments are unused."""
        unused_kwargs = set(kwargs) - set(used_args)
        if unused_kwargs:
            raise AssertionError(
                "{} {} not used in formatting string.".format(
                    sorted(unused_kwargs),
                    ["was", "were"][min(1, len(unused_kwargs)-1)]
                )
            )

def main():
    StrictFormatter().format("xxx", foo="foo")

if "__main__" == __name__:
    main()

gives

vulture_check.py:4: unused function 'check_unused_args' (60% confidence)

but when you run it you see that the code is in fact being exercised. Thoughts?

@jendrikseipp
Copy link
Owner

Thanks for the report! Static analyzers like Vulture can't detect this kind of code use. Instead, we'll have to add a whitelist for the methods of string.Formatter (https://docs.python.org/3/library/string.html).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants