KotlinIsland / KotlinIsland/basedtyping
better way to check if types are equal
- Dominant language
- Python
- Stars
- 12
- Forks
- 2
- PR merge metrics
- No merged PRs in 30d
Description
better way to check if types are equal
https://github.com/KotlinIsland/basedtyping/blob/4d116fdc491bad8c8de6c67960fff19e6d05b1ac/tests/test_never_type/test_typetime.py#L10
```python
from typing import TYPE_CHECKING, NoReturn, cast
if TYPE_CHECKING:
# these are just type-time tests, not real life pytest tests. they are only run by mypy
from basedtyping import Never
from basedtyping.typetime_only import assert_type
def test_never_equals_noreturn() -> None:
# TODO: better way to check if types are equal
assert_type[NoReturn](cast(Never, 1))
assert_type[Never](cast(NoReturn, 1))
def test_valid_type_hint() -> None:
_never: Never
def test_cant_assign_to_never() -> None:
_never: Never = 1 # type: ignore[assignment]
def test_cant_subtype() -> None:
class _A(Never): # type: ignore[misc]
...
def test_type_never() -> None:
"""``type[Never]`` is invalid as ``Never`` is not a ``type``.
Should actually be:
``_t: type[Never] # type: ignore[type-var]``
due to https://github.com/python/mypy/issues/11291
So current implementation resembles an xfail.
"""
_t: type[Never]
```
c98f3e2d42fde0a2b4e144afad3428a336f987d4
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.