-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
With such code:
import constclasses as cc
@cc.const_class(with_strict_types=True)
class Widget:
first: int
second: int
widget = Widget(first=10, second=20)Python throws an error constclasses.ccerror.InitializationError: Invalid number of arguments: expected 2 - got 0.
Extending the const_class decorator with with_kwargs=True in such way:
import constclasses as cc
@cc.const_class(with_strict_types=True, with_kwargs=True)
class Widget:
first: int
second: int
widget = Widget(first=10, second=20)seems to solve the problem, but then the Widget cannot be created without using named arguments, e.g. with widget = Widget(1, 2), since it throws:
E TypeError: Attribute value does not match the declared type:
E attribute: first, declared type: <class 'int'>, actual type: <class 'NoneType'>Could the constclasses.const_class be somehow extended to support both named and unnamed arguments, so the same class can be reused?
Metadata
Metadata
Assignees
Labels
No labels