Skip to content

Using typing.Annotated #1275

Closed as not planned
Closed as not planned

Description

@AdrianSosic

Hi, I'm not sure if this has been already discussed in some other context (and please just close if this is a duplicate) but I was wondering if there is already some debate on whether or not it makes sense to also support using typing.Annotated for attrs. For example, I've seen that pydantic uses the mechanism to allow binding validation to types instead of attributes, which I think is a neat concept that allows reusing the same semantic meaning across different contexts/classes. And I've already had several situations in my code where such a mechanism would have been useful, e.g. when attributes of different classes should undergo the exact same conversion/validation logic.

Are there any plans for this in attrs already?

Activity

  1. hynek commented on Apr 9, 2024

    @hynek
    Member

    There's no plans underway, no. The whole field seems also a bit in flux tbh but @Tinche might have opinions.

  2. added
    TypingTyping/stub/Mypy/PyRight related bugs.
    on May 8, 2024
  3. AdrianSosic commented on May 21, 2024

    @AdrianSosic
    Author

    We've just added another module to our code where the same combination of type hint + field definition is repeated all over the place, which again reminded me of how useful the typing.Annotated could be in many situations. Just wanted to ask again if the two of you already could make your minds about whether you see this on the roadmap or not. I think it would also help many people transition from pydantic to attrs, who are already used to that syntax, in fact ...

  4. dlax commented on May 21, 2024

    @dlax
    Contributor

    Duplicate of #775

  5. AdrianSosic commented on May 28, 2024

    @AdrianSosic
    Author

    Hi @dlax, thanks for tagging!

  6. hynek commented on Jul 24, 2024

    @hynek
    Member

    closing in favor of #775

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    TypingTyping/stub/Mypy/PyRight related bugs.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions