pythonoopflaskabstract-classpylint

Pylint unnecessary pass statement for abstract method


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?


Solution

  • 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.