Skip to content
This repository was archived by the owner on Feb 6, 2025. It is now read-only.

Add Literal to typing import shim, change to mypy-friendly approach. #926

Merged
merged 2 commits into from
Sep 22, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions graphql_compiler/typedefs.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
# Copyright 2020-present Kensho Technologies, LLC.
import sys
from typing import Union

from graphql import GraphQLList, GraphQLNonNull, GraphQLScalarType


# The below code is an import shim for TypedDict: we don't want to conditionally import it from
# every file that needs it. Instead, we conditionally import it here and then import from this file
# in every other location where this is needed.
# The below code is an import shim for TypedDict and Literal: we don't want to conditionally import
# them from every file that needs them. Instead, we conditionally import them here and then import
# from this file in every other location where they are needed.
#
# Hence, the "unused import" warnings on TypedDict here are false-positives.
try:
from typing import TypedDict # noqa # pylint: disable=unused-import
except ImportError: # TypedDict was only added to typing in Python 3.8
from typing_extensions import TypedDict # noqa # pylint: disable=unused-import
# We prefer the explicit sys.version_info check instead of the more common try-except ImportError
# approach, because at the moment mypy seems to have an easier time with the sys.version_info check:
# https://github.com/python/mypy/issues/1393
#
# Hence, the "unused import" warnings here are false-positives.
if sys.version_info[:2] >= (3, 8):
# TypedDict and Literal were only added to typing in Python 3.8
from typing import Literal, TypedDict # noqa # pylint: disable=unused-import
else:
from typing_extensions import Literal, TypedDict # noqa # pylint: disable=unused-import


# The compiler's supported GraphQL types for query arguments. The GraphQL type of a query argument
Expand Down