Repository: litestar-org/litestar

Issue:
Bug: cannot use custom typed state
Pydantic validation fails for custom typed state:

```python
from starlite import State, get

class MyState(State):
    my_value: int

@get("/path")
def handler(state: MyState) -> None:
    return None
```

This will raise a validation error. 


Discussion:

Resolving patch:
diff --git a/starlite/signature.py b/starlite/signature.py
--- a/starlite/signature.py
+++ b/starlite/signature.py
@@ -39,6 +39,8 @@
 
 
 UNDEFINED_SENTINELS = {Undefined, Signature.empty}
+SKIP_NAMES = {"self", "cls"}
+SKIP_VALIDATION_NAMES = {"request", "socket", "state"}
 
 
 class SignatureModel(BaseModel):
@@ -203,10 +205,6 @@ class SignatureModelFactory:
         "plugins",
         "signature",
     )
-    # names of fn params not included in signature model.
-    SKIP_NAMES = {"self", "cls"}
-    # names of params always typed `Any`.
-    SKIP_VALIDATION_NAMES = {"request", "socket"}
 
     def __init__(self, fn: "AnyCallable", plugins: List["PluginProtocol"], dependency_names: Set[str]) -> None:
         if fn is None:
@@ -321,7 +319,7 @@ def signature_parameters(self) -> Generator[SignatureParameter, None, None]:
         Generator[SignatureParameter, None, None]
         """
         for name, parameter in self.signature.parameters.items():
-            if name in self.SKIP_NAMES:
+            if name in SKIP_NAMES:
                 continue
             yield SignatureParameter(self.fn_name, name, parameter)
 
@@ -335,7 +333,7 @@ def should_skip_parameter_validation(self, parameter: SignatureParameter) -> boo
         Returns:
             A boolean indicating whether injected values for this parameter should not be validated.
         """
-        return parameter.name in self.SKIP_VALIDATION_NAMES or should_skip_dependency_validation(parameter.default)
+        return parameter.name in SKIP_VALIDATION_NAMES or should_skip_dependency_validation(parameter.default)
 
     def create_signature_model(self) -> Type[SignatureModel]:
         """Constructs a `SignatureModel` type that represents the signature of


Test patch:
diff --git a/tests/kwargs/test_reserved_kwargs_injection.py b/tests/kwargs/test_reserved_kwargs_injection.py
--- a/tests/kwargs/test_reserved_kwargs_injection.py
+++ b/tests/kwargs/test_reserved_kwargs_injection.py
@@ -1,4 +1,4 @@
-from typing import Any, List, Optional, cast
+from typing import Any, List, Optional, Type, Union, cast
 
 import pytest
 from pydantic import BaseModel, Field
@@ -21,12 +21,18 @@
 from tests import Person, PersonFactory
 
 
-def test_application_state_injection() -> None:
+class CustomState(State):
+    called: bool
+    msg: str
+
+
+@pytest.mark.parametrize("state_typing", [State, CustomState])
+def test_application_state_injection(state_typing: Union[Type[State], CustomState]) -> None:
     @get("/", media_type=MediaType.TEXT)
-    def route_handler(state: State) -> str:
+    def route_handler(state: state_typing) -> str:  # type: ignore
         assert state
-        state.called = True  # this should not modify the app state
-        return cast("str", state.msg)  # this shows injection worked
+        state.called = True  # type: ignore
+        return cast("str", state.msg)  # type: ignore
 
     with create_test_client(route_handler) as client:
         client.app.state.msg = "hello"
diff --git a/tests/kwargs/test_validations.py b/tests/kwargs/test_validations.py
--- a/tests/kwargs/test_validations.py
+++ b/tests/kwargs/test_validations.py
@@ -16,6 +16,7 @@
     websocket,
 )
 from starlite.constants import RESERVED_KWARGS
+from starlite.signature import SKIP_VALIDATION_NAMES
 
 
 def my_dependency() -> int:
@@ -90,7 +91,7 @@ def test_raises_when_reserved_kwargs_are_misused(reserved_kwarg: str) -> None:
 
     # these kwargs are set to Any when the signature model is generated,
     # because pydantic can't handle generics for non pydantic classes. So these tests won't work for aliased parameters.
-    if reserved_kwarg not in ["socket", "request"]:
+    if reserved_kwarg not in SKIP_VALIDATION_NAMES:
         exec(f"async def test_fn({reserved_kwarg}: int = Parameter(query='my_param')) -> None: pass")
         handler_with_aliased_param = decorator("/")(locals()["test_fn"])
         with pytest.raises(ImproperlyConfiguredException):