-
-
Notifications
You must be signed in to change notification settings - Fork 407
Open
Description
I am learning to use the attrs package and I have two questions to ask:
- When using 'converter' to modify the input type when creating a property, it will cause IDE to make an error in judging the input type. For example, I originally wanted this input to be
int, but it prompted me that it should bestr. Is there any good way to solve this problem?
- When using the
class xxxxto create traditional classes, it is common to add instantiation comments in the__init__method. Now, with attrs, the instantiation process no longer has parameter prompts. Is there any other good way to solve the problem of document prompts during instantiation besides adding comments directly to the class?
import attrs
@attrs.define
class Com:
"""
Initialize Com2 instance.
:param code: Code of the Com2 instance.
"""
code: str = attrs.field(converter=str)
class Com2:
def __init__(self, code: int):
"""
Initialize Com2 instance.
:param code: Code of the Com2 instance.
"""
self.code: str = str(code)
if __name__ == '__main__':
com = Com(code=1)
com2 = Com2(code=2)Metadata
Metadata
Assignees
Labels
No labels