1

I have an abstract method which just includes a pass statement, as the method implementation is in another class that inherits from this abstract class. Here is the method:

@abstractmethod
def parse_sun_times(self, times_as_strings: Dict[str, str]) -> SunTimes:
    """
    Parses a dictionary of time strings into a SunTimes object.

    Args:
        times_as_strings (Dict[str, str]): A dictionary containing time strings as values and
        sun phases as keys

    Returns:
        SunTimes: An object representing parsed sunrise, sunset, and twilight times.
    """
    pass

Pylint is giving the warning "unnecessary pass statement". Is there some way I can signify to pylint that this is an abstract method, or do I just have to disable the warning manually?

8
  • 1
    Does the same error occur if you use ... instead of pass? Commented Nov 22, 2024 at 17:41
  • Yes, I get the unnecessary ellipses constant warning Commented Nov 22, 2024 at 17:44
  • 1
    The docs appear to assume you already have a docstring as the first element after the signature (which would explain the recommendation to simply remove it, definition would still be syntactically complete) Commented Nov 22, 2024 at 17:50
  • 1
    And I presume that the pylint warning only comes when you have that docstring. I can't believe it would recommend invalid syntax. Commented Nov 22, 2024 at 17:52
  • 1
    Yes, this is correct! Removing the docstring removed the warning, and vice versa with the pass statement! Commented Nov 22, 2024 at 18:00

1 Answer 1

4

As mentioned in Mathias' comment, because there is a docstring as the first element after the signature, the definition is syntactically complete without the need for a pass statement. To remove the warning, either remove the docstring or the pass statement, as it is unnecessary to include both.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.