Skip to content

fix: use origin identity check for types.UnionType in _unwrap_optional#801

Merged
radu-mocanu merged 1 commit intomainfrom
fix/union-type-origin-check
Apr 24, 2026
Merged

fix: use origin identity check for types.UnionType in _unwrap_optional#801
radu-mocanu merged 1 commit intomainfrom
fix/union-type-origin-check

Conversation

@radu-mocanu
Copy link
Copy Markdown
Collaborator

@radu-mocanu radu-mocanu commented Apr 23, 2026

Summary

  • replace isinstance(annotation, types.UnionType) with origin is types.UnionType in _unwrap_optional
  • add regression test for X | None (PEP 604) field annotations

Why

the previous fix used isinstance on the annotation object directly, which runs on every non-generic annotation (when get_origin returns None) and could raise on pathological annotations. checking origin is types.UnionType is equivalent, safer, and consistent with how the typing.Union case is already handled.

Development Package

  • Use uipath pack --nolock to get the latest dev build from this PR (requires version range).
  • Add this package as a dependency in your pyproject.toml:
[project]
dependencies = [
  # Exact version:
  "uipath-langchain==0.10.4.dev1008014385",

  # Any version from PR
  "uipath-langchain>=0.10.4.dev1008010000,<0.10.4.dev1008020000"
]

[[tool.uv.index]]
name = "testpypi"
url = "https://test.pypi.org/simple/"
publish-url = "https://test.pypi.org/legacy/"
explicit = true

[tool.uv.sources]
uipath-langchain = { index = "testpypi" }

[tool.uv]
override-dependencies = [
    "uipath-langchain>=0.10.4.dev1008010000,<0.10.4.dev1008020000",
]

@radu-mocanu radu-mocanu force-pushed the fix/union-type-origin-check branch from 42382b4 to 9bdf8ea Compare April 24, 2026 09:36
@radu-mocanu radu-mocanu force-pushed the fix/union-type-origin-check branch from 9bdf8ea to a3dd234 Compare April 24, 2026 09:37
@radu-mocanu radu-mocanu enabled auto-merge (squash) April 24, 2026 09:38
@radu-mocanu radu-mocanu merged commit 9cde58c into main Apr 24, 2026
43 of 45 checks passed
@radu-mocanu radu-mocanu deleted the fix/union-type-origin-check branch April 24, 2026 09:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants