Skip to content

Incorrect coder inference for List and Tuple typehints. #18788

@kennknowles

Description

@kennknowles

We seem to use a FastPrimitivesCoder for List and Tuple typehints with homogenous element types, and fail to do the type checking:


inputs = (1, "a string")
coder = typecoders.registry.get_coder(typehints.Tuple[int, str])
print(type(coder))
# <class 'apache_beam.coders.coders.TupleCoder'>
encoded = coder.encode(inputs) 
# Fails: TypeError:
an integer is required - correct behaviour

coder = typecoders.registry.get_coder(typehints.Tuple[int,
...]) # A tuple of integers.
print(type(coder)) # <class 'apache_beam.coders.coders.FastPrimitivesCoder'>
- wrong coder?
encoded = coder.encode(inputs)
# No errors - incorrect behavior.

coder = typecoders.registry.get_coder(typehints.List[int])
# A list of integers.
print(type(coder)) # <class 'apache_beam.coders.coders.FastPrimitivesCoder'>
- wrong coder?
encoded = coder.encode(inputs)
# No errors - incorrect behavior.

Imported from Jira BEAM-4441. Original Jira may contain additional context.
Reported by: tvalentyn.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions