Repository: pydantic/pydantic

Issue:
Cannot use Literal from standard library in 3.8
# Bug

* OS: macOS
* Python version `import sys; print(sys.version)`: 3.8.0
* Pydantic version `import pydantic; print(pydantic.VERSION)`: 1.1.1

Annotating models with the built-in literal in Python 3.8 in the absence of `typing_extensions` does not work because `is_literal_type` only checks if `Literal` is available from `typing_extensions`.  Please see the snippet below.

```term
$ cat test.py
from typing import Literal
from pydantic import BaseModel


class Foo(BaseModel):
    bar: Literal['']


print('ok!')
$ python3 test.py
Traceback (most recent call last):
  File "test.py", line 5, in <module>
    class Foo(BaseModel):
  File "/Users/layday/code/instawow/.venvs/3.8/lib/python3.8/site-packages/pydantic/main.py", line 192, in __new__
    fields[ann_name] = ModelField.infer(
  File "/Users/layday/code/instawow/.venvs/3.8/lib/python3.8/site-packages/pydantic/fields.py", line 260, in infer
    return cls(
  File "/Users/layday/code/instawow/.venvs/3.8/lib/python3.8/site-packages/pydantic/fields.py", line 237, in __init__
    self.prepare()
  File "/Users/layday/code/instawow/.venvs/3.8/lib/python3.8/site-packages/pydantic/fields.py", line 307, in prepare
    self._type_analysis()
  File "/Users/layday/code/instawow/.venvs/3.8/lib/python3.8/site-packages/pydantic/fields.py", line 359, in _type_analysis
    if issubclass(origin, Tuple):  # type: ignore
  File "/nix/store/mnl1njrv6g2jcs69kq0cy19766kcgc5n-python3-3.8.0/lib/python3.8/typing.py", line 771, in __subclasscheck__
    return issubclass(cls, self.__origin__)
TypeError: issubclass() arg 1 must be a class
$ pip3 install typing_extensions
Collecting typing_extensions
  Using cached https://files.pythonhosted.org/packages/03/92/705fe8aca27678e01bbdd7738173b8e7df0088a2202c80352f664630d638/typing_extensions-3.7.4.1-py3-none-any.whl
Installing collected packages: typing-extensions
Successfully installed typing-extensions-3.7.4.1
WARNING: You are using pip version 19.2.3, however version 19.3.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
$ python3 test.py
ok!
```



Discussion:
Thanks for reporting. PR welcome. 

Resolving patch:
diff --git a/pydantic/fields.py b/pydantic/fields.py
--- a/pydantic/fields.py
+++ b/pydantic/fields.py
@@ -28,11 +28,6 @@
 from .utils import PyObjectStr, Representation, lenient_issubclass, sequence_like
 from .validators import constant_validator, dict_validator, find_validators, validate_json
 
-try:
-    from typing_extensions import Literal
-except ImportError:
-    Literal = None  # type: ignore
-
 Required: Any = Ellipsis
 
 if TYPE_CHECKING:
diff --git a/pydantic/typing.py b/pydantic/typing.py
--- a/pydantic/typing.py
+++ b/pydantic/typing.py
@@ -48,11 +48,16 @@ def evaluate_forwardref(type_, globalns, localns):  # type: ignore
 
     AnyCallable = TypingCallable[..., Any]
 
-try:
-    from typing_extensions import Literal
-except ImportError:
-    Literal = None  # type: ignore
-
+if sys.version_info < (3, 8):
+    if TYPE_CHECKING:
+        from typing_extensions import Literal
+    else:  # due to different mypy warnings raised during CI for python 3.7 and 3.8
+        try:
+            from typing_extensions import Literal
+        except ImportError:
+            Literal = None
+else:
+    from typing import Literal
 
 if TYPE_CHECKING:
     from .fields import ModelField
diff --git a/pydantic/utils.py b/pydantic/utils.py
--- a/pydantic/utils.py
+++ b/pydantic/utils.py
@@ -21,11 +21,6 @@
 
 from .typing import AnyType, display_as_type
 
-try:
-    from typing_extensions import Literal
-except ImportError:
-    Literal = None  # type: ignore
-
 if TYPE_CHECKING:
     from .main import BaseModel  # noqa: F401
     from .typing import AbstractSetIntStr, DictIntStrAny, IntStr, ReprArgs  # noqa: F401


Test patch:
diff --git a/tests/test_errors.py b/tests/test_errors.py
--- a/tests/test_errors.py
+++ b/tests/test_errors.py
@@ -6,11 +6,7 @@
 
 from pydantic import UUID1, BaseConfig, BaseModel, PydanticTypeError, ValidationError, conint, errors, validator
 from pydantic.error_wrappers import flatten_errors, get_exc_type
-
-try:
-    from typing_extensions import Literal
-except ImportError:
-    Literal = None
+from pydantic.typing import Literal
 
 
 def test_pydantic_error():