from dataclasses import dataclass, field
@dataclass
class MyClass:
x = field()
but it produces an error because fields need to be declared with a type annotation. This is the GvR recommended way to get around it: @dataclass
class MyClass:
x: object
You could use the typing.Any type instead of object, but then you need to import a whole typing library to use untyped dataclasses. I highly prefer the former code block. fn(1)(2)(3)
That's a big drawback for me. Libraries like Ramda allow one or more arguments per function call: fn(1, 2, 3) === fn(1, 2)(3) === fn(1)(2, 3)
That's what makes the verbosity unbearable, as each type of call needs its own type. def find(predicate, iterable, default=None):
"""Returns the first value that matches predicate, otherwise default=None"""
return next(
(x for x in iterable if predicate(x)),
default
)
Which turns the expression to find(lambda x: 'widgets' in x, mixed_widgets)['widgets']