Repository: litestar-org/litestar

Issue:
Local run of `mypy` produces unexpected results
### Description

Mypy produces unexpected failures locally, but the CI job passes: https://github.com/litestar-org/litestar/actions/runs/5561581892/jobs/10159348023?pr=1959

I think that this happens because `.pre-commit-config` and local mypy settings are not in sync.
I will fix that.

### URL to code causing the issue

_No response_

### MCVE

_No response_

### Steps to reproduce

```bash
1. `poetry install --with lint -E full`
2. `poetry run mypy litestar`
```


### Screenshots

_No response_

### Logs

```bash
» mypy litestar      
litestar/contrib/jwt/jwt_token.py:115: error: Redundant cast to "str"  [redundant-cast]
litestar/_signature/models/attrs_signature_model.py:43: error: Skipping analyzing "pytimeparse.timeparse": module is installed, but missing library stubs or py.typed marker  [import]
litestar/_signature/models/attrs_signature_model.py:43: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
litestar/middleware/compression.py:29: error: Skipping analyzing "brotli": module is installed, but missing library stubs or py.typed marker  [import]
litestar/contrib/mako.py:19: error: Skipping analyzing "mako": module is installed, but missing library stubs or py.typed marker  [import]
litestar/contrib/mako.py:24: error: Skipping analyzing "mako.exceptions": module is installed, but missing library stubs or py.typed marker  [import]
litestar/contrib/mako.py:25: error: Skipping analyzing "mako.lookup": module is installed, but missing library stubs or py.typed marker  [import]
litestar/contrib/mako.py:28: error: Skipping analyzing "mako.template": module is installed, but missing library stubs or py.typed marker  [import]
litestar/cli/commands/schema.py:5: error: Skipping analyzing "jsbeautifier": module is installed, but missing library stubs or py.typed marker  [import]
Found 8 errors in 5 files (checked 303 source files)
```


### Litestar Version

`main`

### Platform

- [ ] Linux
- [X] 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/1960">
<picture>
  <source media="(prefers-color-scheme: dark)" srcset="https://polar.sh/api/github/litestar-org/litestar/issues/1960/pledge.svg?darkmode=1">
  <img alt="Fund with Polar" src="https://polar.sh/api/github/litestar-org/litestar/issues/1960/pledge.svg">
</picture>
</a>
<!-- POLAR PLEDGE BADGE END -->



Discussion:

Resolving patch:
diff --git a/litestar/contrib/jwt/jwt_token.py b/litestar/contrib/jwt/jwt_token.py
--- a/litestar/contrib/jwt/jwt_token.py
+++ b/litestar/contrib/jwt/jwt_token.py
@@ -3,7 +3,7 @@
 import dataclasses
 from dataclasses import asdict, dataclass, field
 from datetime import datetime, timezone
-from typing import TYPE_CHECKING, Any, cast
+from typing import TYPE_CHECKING, Any
 
 from jose import JWSError, JWTError, jwt
 
@@ -112,11 +112,8 @@ def encode(self, secret: str, algorithm: str) -> str:
             ImproperlyConfiguredException: If encoding fails.
         """
         try:
-            return cast(
-                "str",
-                jwt.encode(
-                    claims={k: v for k, v in asdict(self).items() if v is not None}, key=secret, algorithm=algorithm
-                ),
+            return jwt.encode(
+                claims={k: v for k, v in asdict(self).items() if v is not None}, key=secret, algorithm=algorithm
             )
         except (JWTError, JWSError) as e:
             raise ImproperlyConfiguredException("Failed to encode token") from e


Test patch: