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 TRY300 when there is no except clause #3632

Closed
Czaki opened this issue Mar 20, 2023 · 1 comment · Fixed by #3634
Closed

False positive TRY300 when there is no except clause #3632

Czaki opened this issue Mar 20, 2023 · 1 comment · Fixed by #3634
Labels
bug Something isn't working

Comments

@Czaki
Copy link
Contributor

Czaki commented Mar 20, 2023

In napari we have such a function https://github.com/napari/napari/blob/ab885957fb5a2220a3078851ad7dc97a7a82cc05/napari/utils/misc.py#L253

def formatdoc(obj):
    """Substitute globals and locals into an object's docstring."""
    frame = inspect.currentframe().f_back
    try:
        obj.__doc__ = obj.__doc__.format(
            **{**frame.f_globals, **frame.f_locals}
        )
        return obj
    finally:
        del frame

The TRY300 is reported on return obj. But the else clause is available only when the except clause is present (there needs to be at least one). So TRY300 should not be reported if there is no except clause. Or it should have different text describing that.

Currently:

TRY300 Consider moving this statement to an `else` block

Possible:

TRY300 Consider moving this statement after `try: finally:`
@JonathanPlasse
Copy link
Contributor

I would like to work on it.

@charliermarsh charliermarsh added the bug Something isn't working label Mar 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants