Hacker News new | ask | show | jobs
by nknight 5261 days ago
> It's not possible to mandate the usage of keyword attributes in Python 2

That's not completely true, but it's inconvenient. If you're prepared to go the kwargs route, calling with positional arguments raises a TypeError:

    >>> def foo(**kwargs):
    ...  print(kwargs['a'], kwargs['b'])
    ... 
    >>> foo(1, 2)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: foo() takes exactly 0 arguments (2 given)
    >>> foo(a=1, b=2)
    (1, 2)
You have to manually check for required parameters, though, and assign any necessary defaults.
1 comments

> That's not completely true, but it's inconvenient. If you're prepared to go the kwargs route

Ah true, I'd not thought about using kwargs only.

> You have to manually check for required parameters, though, and assign any necessary defaults.

Yeah, and you likely lose parameters management in the IDE.