Skip to content

typing.Set (built-in set type) is aliased to collections.abc.Set (abstract set) #264

@layday

Description

@layday
  • cattrs version: 22.1.0
  • Python version: 3.8
  • Operating System: macOS

Description

GenConverter's unstruct_collection_overrides param expects a collections.abc.Set in Python 3.9+ and a typing.Set in Python 3.8 and below. typing.Set is a generic version of the set built-in; the typing module's equivalent of collections.abc.Set is AbstractSet. In 3.8 and below, collections.abc.Set is silently ignored and typing.Set incorrectly applies to all set types. I would expect collections.abc.Set to work on all (supported) Python versions, especially considering that paremetrised overrides are not supported (Set[...] has no effect).

What I Did

from collections.abc import Set

converter = GenConverter(unstruct_collection_overrides={Set: sorted})
converter.unstructure(frozenset(()))  # Not converted to a list on Python 3.8

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