6

I wrote some Python code which works but Pylint doesn't like the star. It keeps telling me:

Used * or ** magic (star-args)

Is it possible to write my code without the star? Some info: I'm using lxml; self.xml is an objectified XML file.

@property
def version_string(self):
    '''Return the version as a string.'''
    try:
        version_format = self.xml.version.get("format")
    except AttributeError:
        return None
    version_values = (v.text for v in self.xml.version.v)
    return version_format.format(*version_values)
Hooked
  • 84,485
  • 43
  • 192
  • 261
Mr.Yeah
  • 1,054
  • 2
  • 9
  • 21

3 Answers3

11

There's nothing wrong with the splat operator. Without knowing what the version_format function does, it's not possible to say if you could pass an iterable, or iterate the function directly, but frankly there's no reason to.

Marcin
  • 48,559
  • 18
  • 128
  • 201
  • 6
    I totally agree, nothing wrong with using argument unpacking to format strings. I'd simply [disable that PyLint warning](http://stackoverflow.com/a/20639659/1599111). – Lukas Graf May 18 '14 at 19:29
7

If you don't like that pylint warning, disable it. It was originally introduced because having lots of

def some_function(*args, **kwargs):
    pass

lowers the readability / maintainability of the code.

gurney alex
  • 13,247
  • 4
  • 43
  • 57
  • That seems like a bug in their specifications, to catch a splat call, rather than a splat function definition. – Marcin May 19 '14 at 13:07
4

star-args (W0142) is no longer present in pylint (at least since version 1.4.3). It appears to have been removed fairly recently.

Six
  • 5,122
  • 3
  • 29
  • 38