Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Use type guards #183

Copy link
Copy link
Closed
Closed
Copy link
@helderco

Description

@helderco
Issue body actions

As an example I specifically need them in type/definition.py to correctly narrow down the types in a codegen tool. In the meantime I've reimplemented these functions:

def is_required_type(t: Any) -> TypeGuard[GraphQLNonNull]:
    return isinstance(t, GraphQLNonNull)


def is_list_type(t: Any) -> TypeGuard[GraphQLList]:
    return isinstance(t, GraphQLList)


def is_wrapping_type(t: Any) -> TypeGuard[GraphQLWrappingType]:
    return isinstance(t, GraphQLWrappingType)


def is_scalar_type(t: Any) -> TypeGuard[GraphQLScalarType]:
    return isinstance(t, GraphQLScalarType)


def is_input_object_type(t: Any) -> TypeGuard[GraphQLInputObjectType]:
    return isinstance(t, GraphQLInputObjectType)


def is_object_type(t: Any) -> TypeGuard[GraphQLObjectType]:
    return isinstance(t, GraphQLObjectType)

I thought the isinstance would be enough for the type checker to infer in these cases but if the return type is bool in these functions they're not narrowed.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.