This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from typing import Any, Generic, TypeVarTuple, TypeVar, Concatenate, Tuple, Unpack, ParamSpec, Optional, TypedDict, Required, NotRequired | |
| T = TypeVar('T') | |
| TT = TypeVarTuple('TT') | |
| TTF = TypeVarTuple('TTF') | |
| P = ParamSpec('P') | |
| class Base(): | |
| @classmethod | |
| def do(cls, *args, **kwargs): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from typing import Never | |
| def very_sound_function() -> float: | |
| y: list[Never] = [] | |
| return next(iter(y)).startswith("xyz") # type checker approved! | |
| # ^^^^^^^^^^^^^ this may have been a good place to error | |
| # if we really believed Never was uninhabited. | |
| def make_never() -> Never: | |
| while True: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from typing import Never | |
| def foo() -> Never: | |
| while True: | |
| pass | |
| def baz(arg: object) -> None: pass | |
| def bar() -> None: | |
| return baz(foo()) # undetected unreachable code |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from typing import Never | |
| def foo() -> Never: | |
| while True: | |
| pass | |
| def bar() -> tuple[int, ...]: | |
| return (foo(),) # undetected unreachable code | |
| x = bar() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from typing import Never | |
| def foo() -> Never: | |
| while True: | |
| pass | |
| def bar() -> tuple[int, ...]: | |
| return (foo(),) # undetected unreachable | |
| x = bar() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import sys | |
| from typing import final | |
| @final | |
| class A: ... | |
| @final | |
| class B: ... | |
| if sys.version_info >= (3, 14): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # mypy: disable-error-code=empty-body | |
| from typing import Protocol, Any | |
| from typing_extensions import Never | |
| from collections.abc import Callable | |
| class KWOnlyFactory(Protocol): | |
| def __call__(self, cls: type[Any], /, **kwargs: Any) -> Never: ... | |
| class Shape(Protocol): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # mypy: disable-error-code=empty-body | |
| from typing import Protocol, Any | |
| from typing_extensions import Never | |
| from collections.abc import Callable | |
| class Factory(Protocol): | |
| def __call__(self, cls: type[Any], /, **kwargs: Any) -> Never: ... | |
| class Shape(Protocol): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # mypy: disable-error-code=empty-body | |
| from typing import Protocol, Any | |
| from typing_extensions import Never | |
| from collections.abc import Callable | |
| class Factory(Protocol): | |
| def __call__(self, cls: type[Any], /, **kwargs: Any) -> Never: ... | |
| class Shape(Protocol): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from typing import Callable, Generic, Literal, Protocol, Type, overload | |
| from typing_extensions import ParamSpec | |
| P = ParamSpec('P') | |
| class Shape[**P](Protocol): | |
| def __init__(self, *args: P.args, **kwargs: P.kwargs) -> None: ... | |
| def area(self) -> float: ... | |
| def perimeter(self) -> float: ... | |