Skip to content

Conversation

Copy link

Copilot AI commented Jan 22, 2026

The code imports _UnionGenericAlias and _GenericAlias from the typing module, which are private APIs not guaranteed to exist across Python versions. In Python 3.8, these members don't exist, causing ImportError: cannot import name '_UnionGenericAlias' from 'typing'.

Changes

  • Replace private imports _UnionGenericAlias and _GenericAlias with public API get_origin
  • Consolidate type checking logic: type(x) == _UnionGenericAlias or type(x) == _GenericAliasget_origin(x) is not None

Before:

from typing import _UnionGenericAlias, List, _GenericAlias

if type(data["type"]["python"]) == _UnionGenericAlias:
    data["type_name"]["python"] = data["type"]["python"].__repr__()
elif type(data["type"]["python"]) == _GenericAlias:
    data["type_name"]["python"] = data["type"]["python"].__repr__()

After:

from typing import List, get_origin

if get_origin(data["type"]["python"]) is not None:
    # Handle generic types (Union, List, etc.)
    data["type_name"]["python"] = data["type"]["python"].__repr__()

This maintains compatibility with Python 3.8+ using only public typing APIs.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Fix ImportError in uv-based package management Fix ImportError from private typing module members in Python 3.8 Jan 22, 2026
Copilot AI requested a review from rororowyourboat January 22, 2026 16:08
@rororowyourboat rororowyourboat marked this pull request as ready for review January 22, 2026 16:10
Copilot AI review requested due to automatic review settings January 22, 2026 16:10
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a Python 3.8 compatibility issue by replacing private typing module members with public APIs. The code previously imported _UnionGenericAlias and _GenericAlias from the typing module, which are internal implementation details that don't exist in Python 3.8, causing ImportError.

Changes:

  • Replace private typing imports (_UnionGenericAlias, _GenericAlias) with public get_origin API
  • Consolidate type checking logic from two separate conditions into a single check using get_origin(x) is not None
  • Add explanatory comment for the generic type handling

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

2 participants