Skip to content

Commit

Permalink
re-export NoReturn as Never instead of using type alias
Browse files Browse the repository at this point in the history
  • Loading branch information
DetachHead committed Jan 8, 2022
1 parent 156f5bd commit 5bb187b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 20 deletions.
11 changes: 4 additions & 7 deletions basedtyping/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
TYPE_CHECKING,
Callable,
Generic,
NoReturn as Never,
Protocol,
Sequence,
TypeVar,
Expand All @@ -14,11 +15,11 @@
cast,
)

# TODO: use typing.NoReturn once https://github.com/python/mypy/issues/11903 is in basedmypy
from mypy_extensions import NoReturn

from basedtyping.runtime_only import OldUnionType

# prevent no-implicit-reexport mypy error
__all__ = ["Never"]

if TYPE_CHECKING:
Function = Callable[..., object] # type: ignore[misc]
"""Any ``Callable``. useful when using mypy with ``disallow-any-explicit``
Expand All @@ -31,10 +32,6 @@
# for isinstance checks
Function = Callable


Never = NoReturn
"""a type that can never exist. this is the narrowest possible type"""

# Unlike the generics in other modules, these are meant to be imported to save you from the boilerplate

T = TypeVar("T")
Expand Down
14 changes: 8 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,16 @@ disable = [
"missing-function-docstring",
"missing-module-docstring",
"missing-class-docstring",
"invalid-name", # https://github.com/PyCQA/pylint/issues/3401
"invalid-name", # https://github.com/PyCQA/pylint/issues/3401
"fixme",
"useless-import-alias", # required when using no-implicit-reexport in mypy
"no-member", # handled by mypy
"inherit-non-class", # handled by mypy, false positive on ReifiedGeneric
"useless-import-alias", # required when using no-implicit-reexport in mypy
"no-member", # handled by mypy
"inherit-non-class", # handled by mypy, false positive on ReifiedGeneric
"too-few-public-methods",
"unused-import", # false negatives + handled by flake8
"duplicate-code", # https://github.com/PyCQA/pylint/issues/214
"unused-import", # false negatives + handled by flake8
"duplicate-code", # https://github.com/PyCQA/pylint/issues/214
"isinstance-second-argument-not-valid-type", # false positive on Never type, handled by mypy
"no-value-for-parameter", # handled by mypy
]
enable = ["useless-suppression", "deprecated-pragma"]

Expand Down
14 changes: 7 additions & 7 deletions tests/test_never_type/test_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,29 @@

from basedtyping import Never, issubform

# xfail tests due to https://github.com/KotlinIsland/basedmypy/issues/24


@mark.xfail
def test_isinstance() -> None:
# https://github.com/python/mypy/issues/11903
assert not isinstance( # type:ignore[misc]
assert not isinstance(
1,
# https://github.com/KotlinIsland/basedmypy/issues/136
Never, # type:ignore[arg-type]
)


# https://github.com/python/mypy/issues/11903 and/or https://github.com/KotlinIsland/basedmypy/issues/24
@mark.xfail
def test_issubform_true() -> None:
"""https://github.com/KotlinIsland/basedtyping/issues/22"""
assert issubform(Never, int) # type:ignore[arg-type]
assert issubform(Never, int)


@mark.xfail
def test_issubform_false() -> None:
assert not issubform(str, Never) # type:ignore[arg-type]
assert not issubform(str, Never)


@mark.xfail
def test_cant_instanciate() -> None:
"""https://github.com/python/mypy/issues/11903"""
with raises(TypeError):
Never() # type:ignore[operator]

0 comments on commit 5bb187b

Please sign in to comment.