Skip to content

attrs plugin should support attrs.evolve #14525

Closed

Description

@ikonst

Feature

In the attrs plugin, we should add special treatment for attrs.evolve.

Pitch

We should validate attr names and types match.

Activity

  1. tmke8 commented on Jan 27, 2023

    @tmke8
    Contributor

    Similar treatment for dataclasses.replace would also be nice. (There was previously PR #14263 but that one only checked that the first argument to replace is a dataclass – which can also be done by just modifying the type stubs.)

  2. ikonst commented on Jan 27, 2023

    @ikonst
    ContributorAuthor

    By modifying the type annotations? I don't think dataclasses have any common base, do they? Or maybe through a protocol?

  3. tmke8 commented on Jan 27, 2023

    @tmke8
    Contributor

    By modifying the type annotations? I don't think dataclasses have any common base, do they? Or maybe through a protocol?

    Yes, @AlexWaygood suggested doing it with a protocol: python/typeshed#9362

  4. AlexWaygood commented on Jan 27, 2023

    @AlexWaygood
    Member

    By modifying the type annotations? I don't think dataclasses have any common base, do they? Or maybe through a protocol?

    Yes, @AlexWaygood suggested doing it with a protocol: python/typeshed#9362

    Applying the same technique to attrs would be difficult unless all type checkers could be counted on to synthesise __attrs_attrs__ attributes for attrs classes in the same way that they can be counted on to synthesise __dataclass_fields__ attributes for classes decorated with @dataclass. Mypy has a custom plugin for attrs, meaning it can be counted on to synthesise this attribute. On the other hand, pyright has (reasonably) resisted adding any special-casing for any third-party libraries.

  5. ikonst commented on Jan 27, 2023

    @ikonst
    ContributorAuthor

    If attrs ships its own type annotations, then they could decide that e.g. you could only used them with mypy and a certain plugin being installed, but I agree we cannot make this decision for typeshed's annotations.

    And for this case, the plugin can easily make this check, and I would have to in #14526 anyway.

  6. AlexWaygood commented on Jan 27, 2023

    @AlexWaygood
    Member

    To be clear, attrs does ship its own type annotations, and typeshed does not have stubs for attrs. If somebody did want to try a solution for attrs along the lines of my dataclasses PR to typeshed, they'd have to implement it in the annotations shipped by attrs, not in typeshed.

  7. added a commit that references this issue on Mar 6, 2023
    bbc9cce
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions