dkanavis

Cool IDE abs

Oct 1st, 2018
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.99 KB | None | 0 0
  1. from abc import ABC, abstractmethod
  2.  
  3. class IField(ABC):
  4.     """
  5.    Filter field abstract class
  6.    """
  7.     name: str
  8.  
  9.     @abstractmethod
  10.     def val(self, event: Event) -> Any:
  11.         """ Abastract value obtainer """
  12.  
  13.  
  14. class Pipe(IField):
  15.     """
  16.    Basic field pipe class
  17.    """
  18.     def __init__(self, field: F):
  19.         self.field = field
  20.         self.name = field.name
  21.  
  22.     def val(self, event: Event):
  23.         raise NotImplementedError("Cannot use Pipe superclass")
  24.  
  25. """
  26. >>>>>>> COOL HERE:
  27. IDE marks next class with a warning if val() method is not implemented, although it's formally implemented by Pipe.
  28. But if I change Pipe's .val() body from raise NotImplementedError to smth like return 1, warning disappears.
  29.  
  30. So IDE treats method's body raise NotImplementedError(...) as enough to satisfy interface's requirements for current
  31. class, but not enough to satisfy them in child classes. It looks wise and well-thought.
  32. """
  33. class Int(Pipe):
  34.     """
  35.     ....................
  36.     """
Advertisement
Add Comment
Please, Sign In to add comment