afonasev / flake8-return

Flake8 plugin for return expressions checking.
MIT License
62 stars 69 forks source link

R503: from function with returns in match/case. #131

Open peterschutt opened 1 year ago

peterschutt commented 1 year ago

Description

Running through pre-commit with flake8-return listed as an additional dependency for the flake8 repo.

This function:

def get_service_for_object(
    obj: events.EventWrapper | markets.MarketWrapper,
) -> events.Service | markets.Service:
    """
    Args:
        obj: The parsed ZF push object.

    Returns:
        Relevant service object for the type.
    """
    match obj:
        case events.EventWrapper():
            return events.Service(obj)
        case markets.MarketWrapper():
            return markets.Service(obj)
        case _:  # pragma: no cover
            raise RuntimeError("Unexpected object type.")

raises R503 missing explicit return at the end of function able to return non-None value.

afonasev commented 1 year ago

Thank you for your issue! Currently, the plugin does not support matching/case expressions. I would be glad to accept your contributions. I'm not sure I'll be able to fix this anytime soon.

peterschutt commented 1 year ago

No worries @afonasev - this is something I'd be interested in looking at but my available bandwidth is also very low.

If I do pick it up I'll ping you again in here to let you know I'm working on it.

ericbn commented 1 year ago

FYI this was fixed in the ruff implementation of flake8-return, here: https://github.com/charliermarsh/ruff/pull/3047