from typing import NamedTuple
Unit = str
Factor = str
_Spec = NamedTuple(
'_Spec',
[('unit', Unit), ('factor', Factor), ('source', str)],
)
class Spec(_Spec):
def __new__(cls, unit, factor, source='derived'):
return super().__new__(cls, unit, factor, source)
def foo() -> Spec:
return Spec('ham', 'spam')
but this gets:
spec.py: note: In function "foo":
spec.py:18: error: Too few arguments for "Spec"
I will see if this can be changed. At first glance it seems to be nontrivial.
(Personally I would prefer defining Spec as a namedtuple and use a make_spec function).
@elazarg still fails in the same way
Perhaps we can improve the lookup in checkmember,py#L443 - look up for __new__ first or otherwise mimic the runtime lookup.
(Raising priority to high since this affects some important internal code)
This now works correctly on master.
Most helpful comment
@elazarg still fails in the same way