Skip to content
This repository was archived by the owner on Feb 23, 2026. It is now read-only.
This repository was archived by the owner on Feb 23, 2026. It is now read-only.

marshalling nested enums from python strings raises a TypeError #103

@software-dov

Description

@software-dov

This requires marshaling from python structures.

Minimal reproduction:

import proto

class Zone(proto.Enum):
    LITTORAL = 1
    MESOPELAGIC = 2
    ABYSSAL = 3
    HADEAN = 4

class Squid(proto.Message):
    zone = proto.Field(Zone, number=1)

class Trawl(proto.Message):
    squids = proto.RepeatedField(Squid, number=1)   # Note: this indirection with the nested field
                                                    # is necessary to trigger the exception.
                                                    # Setting the field in an existing message accepts strings AND
                                                    # checks for valid variants.
                                                    # Similarly, constructing a message directly with a top level 
                                                    # enum field kwarg passed as a string is also handled correctly, i.e.
                                                    # s = Squid(zone="ABYSSAL")
                                                    # does NOT raise an exception.

t = Trawl(squids=[{"zone": "HADEAN"}])

generates

TypeError: 'HADEAN' has type str, but expected one of: int, long

This is related to #52, and most of the implementation will probably be shared.

Metadata

Metadata

Assignees

Labels

priority: p3Desirable enhancement or fix. May not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions