Skip to content

Example tag_hook breaks with cbor2 5.x to 6.x version update #9

Description

@dwmoreau

cbor2 6.0 changed the tag_hook callback signature from tag_hook(decoder, tag) to
tag_hook(tag, immutable). The hook in stream_v2/examples/client.py (and the
example in cbor/dectris-compression-tag.md) therefore fails on cbor2 >= 6 with:

AttributeError: 'bool' object has no attribute 'tag'

Since both versions pass two positional arguments, the hook can support both by
checking which argument is the CBORTag:

def tag_hook(decoder_or_tag, tag_or_immutable=None):
    # cbor2 >= 6 calls tag_hook(tag, immutable); older cbor2 calls tag_hook(decoder, tag)
    tag = decoder_or_tag if isinstance(decoder_or_tag, cbor2.CBORTag) else tag_or_immutable
    tag_decoder = tag_decoders.get(tag.tag)
    return tag_decoder(tag) if tag_decoder else tag

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions