Skip to content

Further resolve already supported types#16

Merged
tuckermcclure merged 4 commits into
mainfrom
tucker/further-resolve-already-supported-types
May 12, 2026
Merged

Further resolve already supported types#16
tuckermcclure merged 4 commits into
mainfrom
tucker/further-resolve-already-supported-types

Conversation

@tuckermcclure
Copy link
Copy Markdown
Member

@tuckermcclure tuckermcclure commented May 12, 2026

Summary

Make PortableStructs.from_dict more robust for generic tuples, dictionaries, tagged values, and structs without keyword constructors.

Motivation

Some parsed YAML/JSON values arrive with only partial type information from the containing field, such as Tuple, NamedTuple, AbstractDict, or Dict. The previous generic loading paths either skipped recursive decoding in some cases, treated dictionary type tags inconsistently, or relied too heavily on keyword constructors.

Changes

  • Add recursive loading support for bare Tuple and generic NamedTuple.
  • Validate tuple lengths instead of silently truncating through zip.
  • Strip type_key entries before redispatching tagged dictionaries.
  • Preserve requested-type validation after resolving type tags.
  • Add explicit dictionary loading paths for:
    • Dict
    • Dict{K,V}
    • OrderedDict
    • OrderedDict{K,V}
    • AbstractDict
    • AbstractDict{K,V} via OrderedDict
  • Avoid guessing concrete implementations for arbitrary abstract dictionary subtypes.
  • Add dict-backed loading for Rational and Complex.
  • Add a narrow positional-constructor fallback for concrete structs whose dict keys exactly match field names.
  • Update README constructor guidance to mention both keyword and positional construction.
  • Remove a misleading type tag from the roses fixture so it remains ordinary dictionary data.

Tests

Added coverage for:

  • generic tuple loading and tuple length mismatch
  • generic named tuple loading with type_key filtering
  • positional construction from exact field-name mappings
  • abstract and concrete dictionary loading behavior
  • rejection of arbitrary abstract dictionary subtypes
  • tagged value resolution and requested-type validation
  • dict-backed Rational and Complex loading

I manually tested that this works with some demanding downstream projects as well.

@tuckermcclure tuckermcclure merged commit e302f26 into main May 12, 2026
6 checks passed
@tuckermcclure tuckermcclure deleted the tucker/further-resolve-already-supported-types branch May 12, 2026 16:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant