Skip to content

Question: Type Annotations and Docs #1483

@OzupeSir

Description

@OzupeSir

I am learning to use the attrs package and I have two questions to ask:

  1. 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 be str. Is there any good way to solve this problem?
Image
  1. When using the class xxxx to 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?
Image Image
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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions