Skip to content

Make GroupedMetadata a protocol? #36

@adriangb

Description

@adriangb

Should we identify GroupedMetadata via an __iter_analyzed_types__ method or something like that instead of a base class?

I think it's a really useful concept, but I fear that it won't be implemented for as much as it could be, for practical reasons:

  1. Name collision with __iter__.
  2. Adding a dependency on annotated-types.
  3. Introduces a class into the other library's class hierarchy, making it maybe impossible in some scenarios (funky things being done with classes, or extension modules).

The first one may be the biggest issue, but it's also got an easy solution: name the method something other than __iter__. But if we're doing that, might as well name it __iter_analyzed_types__ and not require the base class, which also solves the other issues.

We can make this backward compatible by making GroupedMetadata.__iter_analyzed_types__ an alias for GroupedMetadata.__iter__ and GroupedMetadata itself a Protocol. And put a deprecation warning in the latter.

@Zac-HD @samuelcolvin thoughts?

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