Repository: pydantic/pydantic

Issue:
passing `max_items` in `Field` with a `List[Literal["something"]` field raises `TypeError`
### Checks

* [x] I added a descriptive title to this issue
* [x] I have searched (google, github) for similar issues and couldn't find anything
* [x] I have read and followed [the docs](https://pydantic-docs.helpmanual.io/) and still think this is a bug

# Bug

Output of `python -c "import pydantic.utils; print(pydantic.utils.version_info())"`:
```
pydantic version: 1.8.2
pydantic compiled: True
install path: /home/ubuntu/.local/lib/python3.8/site-packages/pydantic
python version: 3.8.5 (default, May 27 2021, 13:30:53)  [GCC 9.3.0]
platform: Linux-5.4.72-microsoft-standard-WSL2-x86_64-with-glibc2.29
optional deps. installed: ['typing-extensions']
```

passing `max_items` raises an error only when the field type is `List[Literal["something"]`.

expectation: passing `max_items` would not raise an error or would raise a more readable error

```py
Python 3.8.5 (default, May 27 2021, 13:30:53)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from pydantic import BaseModel, Field
>>> from typing import List, Literal
>>> class MyModel(BaseModel):
...     it: List[Literal["hi", "hello"]] = Field(max_items=2)
...
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "pydantic/main.py", line 299, in pydantic.main.ModelMetaclass.__new__
  File "pydantic/fields.py", line 410, in pydantic.fields.ModelField.infer
  File "pydantic/schema.py", line 920, in pydantic.schema.get_annotation_from_field_info
  File "pydantic/schema.py", line 1015, in pydantic.schema.get_annotation_with_constraints
  File "pydantic/schema.py", line 967, in pydantic.schema.get_annotation_with_constraints.go
  File "pydantic/schema.py", line 965, in pydantic.schema.get_annotation_with_constraints.go
  File "/usr/lib/python3.8/typing.py", line 774, in __subclasscheck__
    return issubclass(cls, self.__origin__)
TypeError: issubclass() arg 1 must be a class

>>> class MyModel(BaseModel):
...     it: List[Literal["hi", "hello"]] = Field(description="here")
...

>>> class MyModel(BaseModel):
...     it: List[str] = Field(max_items=2)
...
```

Thanks for all help and the work you are doing with this library. We truly appreciate it.



Discussion:

Resolving patch:
diff --git a/pydantic/schema.py b/pydantic/schema.py
--- a/pydantic/schema.py
+++ b/pydantic/schema.py
@@ -951,7 +951,7 @@ def get_annotation_with_constraints(annotation: Any, field_info: FieldInfo) -> T
 
     def go(type_: Any) -> Type[Any]:
         if (
-            is_literal_type(annotation)
+            is_literal_type(type_)
             or isinstance(type_, ForwardRef)
             or lenient_issubclass(type_, (ConstrainedList, ConstrainedSet))
         ):


Test patch:
diff --git a/tests/test_validators.py b/tests/test_validators.py
--- a/tests/test_validators.py
+++ b/tests/test_validators.py
@@ -2,7 +2,7 @@
 from datetime import datetime
 from enum import Enum
 from itertools import product
-from typing import Dict, List, Optional, Tuple
+from typing import Dict, List, Optional, Tuple, Union
 
 import pytest
 from typing_extensions import Literal
@@ -1202,6 +1202,15 @@ class Model(BaseModel):
     ]
 
 
+def test_union_literal_with_constraints():
+    class Model(BaseModel, validate_assignment=True):
+        x: Union[Literal[42], Literal['pika']] = Field(allow_mutation=False)
+
+    m = Model(x=42)
+    with pytest.raises(TypeError):
+        m.x += 1
+
+
 def test_field_that_is_being_validated_is_excluded_from_validator_values(mocker):
     check_values = mocker.MagicMock()