Repository navigation
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces automatic (implicit) conversion of compatible values into target property types during instance initialization from an existing object (
Type(thing)) and when using.assign().Motivation
When initializing nested types from external input (such as JSON or MessagePack payloads), callers previously had to manually map and cast every nested type, enum, set, or error:
Previously, creating a
Jobfrom raw input required explicit boilerplate:With automatic conversion, the same procedure simplifies to:
Scope: When Auto-Conversion Applies
Auto-conversion only occurs when:
Type(thing).assign(...)Direct literal instantiation (
Type{...}) and standard property assignments (instance.prop = val) remain strictly typed and will still raise a type mismatch error:This keeps explicit syntax strict where types are written directly in code, while removing friction when ingesting serialized payloads.
Supported Conversions
intfloat(exact whole numbers only)int(f)(which truncates toward zero), auto-conversion rejects floats with a non-zero fractional part to prevent silent data loss. Other types (such asbool) are not converted.floatint6instead of6.0).regexstrformatted as"/expression/flags"errorstrlike"integer overflow"closurestrformatted as"|args| body"uuidstr(standard UUID format) orbytes(16-byte raw UUID)bytes).enumstr(matching a member name) or the underlying enum member value type (e.g.,int,float,str,bytes, orthing). When astris provided, member names are checked first, followed by member values.thing(Typed Things & Instances)thing({...}): Converted recursively into the target typed thing (thing<...>) or type instance.int): Resolved to the existing instance in the collection, if it exists.setarray([...]), with elements converted to the target set definition type.arrayarray([...]), with elements converted recursively to the target item type.datetimestr(ISO 8601 format)datetimeserializes to an ISO string; accepting the string back makes round-trip serialization seamless.timevalintandfloat(UNIX timestamps)timevalserializes to a numeric UNIX timestamp; acceptingint/floatenables seamless round-trip deserialization.Type of change
How Has This Been Tested?
Checklist: