Repository: litestar-org/litestar

Issue:
Bug: typing error passing list of context managers to `lifespan` app parameter
### Description

Passing a list of pre-constructed async context managers to `lifespan` parameter causes:

```
app.py:20: error: Argument "lifespan" to "Litestar" has incompatible type "list[AioCtxMgr]"; expected "list[Callable[[Litestar], AbstractAsyncContextManager[Any]] | AbstractAsyncContextManager[Any]] | None"  [arg-type]
app.py:20: note: "List" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance
app.py:20: note: Consider using "Sequence" instead, which is covariant
```

### URL to code causing the issue

_No response_

### MCVE

```python
from __future__ import annotations

from typing import Any

from litestar import Litestar


class AioCtxMgr:
    """A dummy context manager."""

    async def __aenter__(self) -> None:
        pass

    async def __aexit__(self, *args: Any) -> None:
        pass


ctx_mgrs = [AioCtxMgr()]
Litestar(route_handlers=[], lifespan=ctx_mgrs)

Litestar(route_handlers=[], lifespan=[AioCtxMgr()])  # OK
```


### Steps to reproduce

```bash
Run mypy on MCVE code.
```


### Screenshots

```bash
"![SCREENSHOT_DESCRIPTION](SCREENSHOT_LINK.png)"
```


### Logs

_No response_

### Litestar Version

2.0.1final0


### Platform

- [X] Linux
- [ ] Mac
- [ ] Windows
- [ ] Other (Please specify in the description above)

<!-- POLAR PLEDGE BADGE START -->
---

## Funding
* If you would like to see an issue prioritized, make a pledge towards it!
* We receive the pledge once the issue is completed & verified

<a href="https://polar.sh/litestar-org/litestar/issues/2348">
<picture>
  <source media="(prefers-color-scheme: dark)" srcset="https://polar.sh/api/github/litestar-org/litestar/issues/2348/pledge.svg?darkmode=1">
  <img alt="Fund with Polar" src="https://polar.sh/api/github/litestar-org/litestar/issues/2348/pledge.svg">
</picture>
</a>
<!-- POLAR PLEDGE BADGE END -->



Discussion:
Can this be typed with `OptionalSequence`?
> Can this be typed with `OptionalSequence`?

I don't see why not :+1: 

Resolving patch:
diff --git a/litestar/app.py b/litestar/app.py
--- a/litestar/app.py
+++ b/litestar/app.py
@@ -212,7 +212,9 @@ def __init__(
         type_encoders: TypeEncodersMap | None = None,
         type_decoders: TypeDecodersSequence | None = None,
         websocket_class: type[WebSocket] | None = None,
-        lifespan: list[Callable[[Litestar], AbstractAsyncContextManager] | AbstractAsyncContextManager] | None = None,
+        lifespan: OptionalSequence[
+            Callable[[Litestar], AbstractAsyncContextManager] | AbstractAsyncContextManager
+        ] = None,
         pdb_on_exception: bool | None = None,
     ) -> None:
         """Initialize a ``Litestar`` application.
@@ -330,7 +332,7 @@ def __init__(
             exception_handlers=exception_handlers or {},
             guards=list(guards or []),
             include_in_schema=include_in_schema,
-            lifespan=lifespan or [],
+            lifespan=list(lifespan or []),
             listeners=list(listeners or []),
             logging_config=cast("BaseLoggingConfig | None", logging_config),
             middleware=list(middleware or []),


Test patch: