Skip to content

attr.resolve_types caches badly with inheritence #842

@A5rocks

Description

@A5rocks

Reproduction case:

from __future__ import annotations

import attr

@attr.define()
class A:
  n: int

@attr.define()
class B(A):
  pass

attr.resolve_types(A)
attr.resolve_types(B)

print(attr.fields(B))

I believe this is because B is somehow inheriting A's __attrs_types_resolved__, even though it gets set later -- which means that it never had its types resolved, but it thinks it has.

This came up when I was using cattrs (I raised an issue there about a trouble I had debugging too :^), which means I do not control the resolution order of types without applying a attr.resolve_types decorator to every class (which might not work -- I'm not sure all my class declarations are in order either...)

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