Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: check for typeddict before class or subclass checks which fail #1160

Merged
merged 1 commit into from
Apr 1, 2024

Conversation

z3z1ma
Copy link
Collaborator

@z3z1ma z3z1ma commented Mar 28, 2024

Description

Just a small fix to ensure union types containing TypedDicts don't fail as they currently do.

Reproducible Example:

class NoopProviderOptions(t.TypedDict): ...


@t.overload
def load_feature_flag_provider(
    provider: None = None,
    options: t.Optional[NoopProviderOptions] = None,
) -> SupportsFFs: ...


@t.overload
def load_feature_flag_provider(
    provider: t.Literal["noop"] = "noop",
    options: t.Optional[NoopProviderOptions] = None,
) -> SupportsFFs: ...


class FileProviderOptions(t.TypedDict):
    path: str


@t.overload
def load_feature_flag_provider(
    provider: t.Literal["file"] = "file",
    options: t.Optional[FileProviderOptions] = None,
) -> SupportsFFs: ...


class HarnessProviderOptions(t.TypedDict):
    api_key: str
    sdk_key: str
    account: str
    organization: str
    project: str


@t.overload
def load_feature_flag_provider(
    provider: t.Literal["harness"] = "harness",
    options: t.Optional[HarnessProviderOptions] = None,
) -> SupportsFFs: ...


class LaunchDarklyProviderOptions(t.TypedDict):
    sdk_key: str


@t.overload
def load_feature_flag_provider(
    provider: t.Literal["launchdarkly"] = "launchdarkly",
    options: t.Optional[LaunchDarklyProviderOptions] = None,
) -> SupportsFFs: ...


@with_config(sections=("feature_flags",))
def load_feature_flag_provider(
    provider: t.Optional[t.Literal["file", "harness", "launchdarkly", "noop"]] = None,
    options: t.Optional[
        t.Union[
            NoopProviderOptions,
            FileProviderOptions,
            HarnessProviderOptions,
            LaunchDarklyProviderOptions,
        ]
    ] = None,
) -> SupportsFFs: ...

The load_feature_flag_provider will fail without my fix because you cannot do isclass or issubclass on a TypedDict...

Related Issues

  • Fixes #...
  • Closes #...
  • Resolves #...

Additional Context

Copy link

netlify bot commented Mar 28, 2024

Deploy Preview for dlt-hub-docs canceled.

Name Link
🔨 Latest commit b0bf9e0
🔍 Latest deploy log https://app.netlify.com/sites/dlt-hub-docs/deploys/6605de3651fb1a00085ea852

@z3z1ma z3z1ma force-pushed the fix/typeddict-in-union branch from abfca01 to b0bf9e0 Compare March 28, 2024 21:16
Copy link
Collaborator

@rudolfix rudolfix left a comment

Choose a reason for hiding this comment

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

LGTM!

@rudolfix rudolfix merged commit dbb5a07 into devel Apr 1, 2024
44 of 53 checks passed
@rudolfix rudolfix deleted the fix/typeddict-in-union branch April 1, 2024 17:44
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