Flagsmith / Flagsmith/flagsmith
Improve typing for WithXPermissions fixtures
- Dominant language
- Python
- Stars
- 6.6k
- Forks
- 567
- Avg merge
- 1d 13h
- Merged PRs (30d)
- 121
Description
The types defined [here](https://github.com/Flagsmith/flagsmith/blob/main/api/tests/types.py#L7-L15) are not valid according to mypy. Currently, all usages of the functions returned by these fixtures raise the following error in mypy's type checking:
```
error: Too few arguments [call-arg]
```
I have already tried moving to using a Protocol definition like the following:
```
class WithEnvironmentPermissionsCallable(Protocol):
def __call__(
self,
permission_keys: Optional[list[str]] = None,
environment_id: Optional[int] = None,
admin: bool = False,
) -> UserEnvironmentPermission: ...
```
However, this just results in a different error:
```
error: Incompatible return value type (got "Callable[[list[str] | None, int | None, bool], UserEnvironmentPermission]", expected "WithEnvironmentPermissionsCallable") [return-value]
note: "WithEnvironmentPermissionsCallable.__call__" has type "Callable[[DefaultArg(list[str] | None, 'permission_keys'), DefaultArg(int | None, 'environment_id'), DefaultArg(bool | None, 'admin')], UserEnvironmentPermission]"
```
Contributor guide
Assessment
This issue has not been assessed yet.