1

I would like to have:

  • Abstract method where you have one keyword arg + variable number of other keyword args
  • Concretions can specify any number of keyword args

My problem is, when I try this, pylint complains with: Parameters differ from overridden 'my_func' method.

Here is an example:

The abstract method

@staticmethod
@abstractmethod
def my_func(config: dict, **kwargs):
    pass

Example concretion

@staticmethod
def my_func(config: dict, special_case: str)
    do_things()
    return

Example call of concretion

my_func(config=config, special_case=special_case)

Is there a way I can construct my abstract method such that I can have:

  • The one keyword arg + variable number of keyword args following
  • Concretions having the one keyword arg + finite number of keyword args following
  • My linter be happy

Thank you in advance!

Intrastellar Explorer
  • 3,005
  • 9
  • 52
  • 119
  • 1
    Please show the entire class which emcompasses my_func, also you should have `self` as first argument in `my_func` – Devesh Kumar Singh Jun 12 '19 at 18:25
  • 3
    `special_case` is not a keyword argument, it is a *positional argument*. The linter is telling you that `my_func()` in the implementation requires more arguments than the abstract method, and that's a violation of the [Liskov substitution principle](https://en.wikipedia.org/wiki/Liskov_substitution_principle). If you want to support keyword arguments that are *optional*, then that's different. – Martijn Pieters Jun 12 '19 at 18:32
  • @DeveshKumarSingh so actually in my implementation it was a `@staticmethod`. I have added that in. – Intrastellar Explorer Jun 12 '19 at 22:12
  • 1
    @MartijnPieters thank you for pointing that out! How would I get a variable number of optional arguments? I suppose that's what I want – Intrastellar Explorer Jun 12 '19 at 22:15
  • 1
    @IntrastellarExplorer: either use [keyword-only arguments](https://stackoverflow.com/questions/33138459/understanding-keyword-only-argument-notation-in-python3-functions) or give your arguments default values. – Martijn Pieters Jun 15 '19 at 16:34

0 Answers0