wemake-services / flake8-eradicate

Flake8 plugin to find commented out or dead code
https://pypi.org/project/flake8-eradicate/
MIT License
310 stars 12 forks source link

Content of f-string interpreted as commented code #266

Open krzysztof3-wisniewski opened 2 years ago

krzysztof3-wisniewski commented 2 years ago

Using flake8-eradicate==1.2.1 On CPython 3.9.13 With flake8==4.0.1 Using the following code as an example

class FooClass(SpamClass):
    def render_html(self) -> str:
        return f"""
        <div>
            <div>
                <h2>
                    spam content <bold>{self.foo.bar().car()}</bold> to <bold>foo</bold><br/>
                </h2>
                <i>
                    “Some quote.”
                    <br/>~Quote author
                <i/>
            <div>
            </div>
                <table>
                    <tbody>
                        <tr>
                            <td><bold>Foo foo</bold></td>
                            <td>{self.bar.foo}</td>
                        </tr>
                        <tr>
                            <td><bold>Bar foo</bold></td>
                            <td>{self.barbar.foo}</td>
                        </tr>
                        <tr>
                            <td><bold>Foo spam</bold></td>
                            <td>
                                <a href="https://service.com/spam/foo/bar/{self.foo.car}">
                                    #{self.foo.car}
                                <a/>
                            </td>
                        </tr>
                        <tr>
                            <td><bold>Spam bar</bold></td>
                            <td>{self.foo()}</td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>
        """

Following snipped, line #{self.foo.car} generates an error Found commented out code flake8(E800)

<a href="https://service.com/spam/foo/bar/{self.foo.car}">
    #{self.foo.car}
<a/>

Which, of course, is not correct because we are not dealing with a comment here. Removing the # from the content makes the error disappear, however, this is not the solution.