apache/beam · error · TypeError
Typehint is not of nullable type
Error message
Typehint is not of nullable type
What it means
get_concrete_type_from_nullable raises TypeError('Typehint is not of nullable type') when given a type hint that is not Optional/nullable (i.e. is_nullable(hint) is False). The helper is meant to unwrap Optional[T] into T and refuses non-nullable inputs rather than guessing.
Solutions
- Guard with apache_beam.typehints.is_nullable(typehint) before calling get_concrete_type_from_nullable.
- Use the hint as-is when it is already non-nullable — no unwrapping is needed.
- Check whether the hint changed from Optional[T] to T upstream and remove the now-unneeded unwrap call.
- For unions that may contain NoneType, normalize with Any/Union handling before calling this helper.
Example fix
# before inner = get_concrete_type_from_nullable(hint) # after inner = get_concrete_type_from_nullable(hint) if is_nullable(hint) else hint
Defensive patterns
Strategy: type-guard
Validate before calling
from apache_beam.typehints import is_nullable, get_concrete_type_from_nullable
def concrete(hint):
return get_concrete_type_from_nullable(hint) if is_nullable(hint) else hint Type guard
def is_optional_hint(h):
return is_nullable(h) Try / catch
try:
inner = get_concrete_type_from_nullable(hint)
except TypeError as e:
if 'not of nullable type' in str(e):
inner = hint
else:
raise Prevention
- Always gate unwrapping with is_nullable
- Handle both Optional[T] and bare T in helper code
- Track hint changes upstream so unwrap calls stay valid
When it happens
Trigger: Calling get_concrete_type_from_nullable on a plain type like int, a Union without NoneType, or any non-Optional hint; helper misuse in code that assumes all incoming hints may be Optional.
Common situations: Pipeline framework code that unwraps optionality before applying conversions but receives raw hints; refactors where a hint stopped being Optional (e.g. Optional[str] changed to str) but the unwrapping call remained.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- An Option type-hint only accepts a single type parameter.
- bad type
- batch type must be List[T] for element type T
- batch type must be np.ndarray or…
- Cannot create Union without a sequence of types.
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/82a84c0d1facb076.
Report an issue: GitHub.
Appendix: source
Thrown at sdks/python/apache_beam/typehints/typehints.py:652
'parameter.')
return Union[py_type, type(None)]
def is_nullable(typehint):
return (
isinstance(typehint, UnionConstraint) and
typehint.contains_type(type(None)) and
len(list(typehint.inner_types())) == 2)
def get_concrete_type_from_nullable(typehint):
if is_nullable(typehint):
for inner_type in typehint.inner_types():
if not type(None) == inner_type:
return inner_type
else:
raise TypeError('Typehint is not of nullable type', typehint)
class TupleHint(CompositeTypeHint):
"""A Tuple type-hint.
Tuple can accept 1 or more type-hint parameters.
Tuple[X, Y] represents a tuple of *exactly* two elements, with the first
being of type 'X' and the second an instance of type 'Y'.
* (1, 2) satisfies Tuple[int, int]
Additionally, one is able to type-hint an arbitary length, homogeneous tuple
by passing the Ellipsis (...) object as the second parameter.
As an example, Tuple[str, ...] indicates a tuple of any length with each
element being an instance of 'str'.
"""View on GitHub (pinned to 12126d8942)