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 ib111 import week_11 # noqa | |
| # Napište čistou funkci, která na základě daného vzoru vytvoří | |
| # množinu všech odpovídajících řetězců. Vzor je tvořený | |
| # alfanumerickými znaky a navíc může obsahovat hranaté závorky – | |
| # znaky ‹[› a ‹]›. Mezi těmito závorkami může stát libovolný počet | |
| # přípustných znaků (krom samotných hranatých závorek) a na daném | |
| # místě se ve výsledném řetězci může nacházet libovolný z těchto | |
| # znaků. Například vzor ‹a[bc]d› reprezentuje řetězce ‹abd› a ‹acd›. |
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 Generic, TypeVar, ParamSpec, Protocol | |
| # ───────────────────────────────────────────────────────────── | |
| # Base type parameters | |
| # ───────────────────────────────────────────────────────────── | |
| P = ParamSpec("P") # Params for __call__ and run | |
| O = TypeVar("O") # Raw output type | |
| S = TypeVar("S", bound=dict) # State type |
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
| class C: | |
| @property | |
| def type(self) -> int: | |
| return 5 | |
| class D(C): | |
| type = 6 | |
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 re | |
| import types | |
| def fun(val: str | re.Pattern | None): | |
| match val: | |
| case str(): | |
| print('string') | |
| case re.Pattern(): | |
| print('pattern') | |
| case types.NoneType(): |
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 Final | |
| def foo(foo: Foo[int | str]) -> None: | |
| pass | |
| def bar(bar: Bar[int | str]) -> None: | |
| pass |
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 | |
| class Foo[**P]: | |
| def __init__(self, fn: Callable[P, int], *args: P.args, **kwargs: P.kwargs) -> None: | |
| self.fn = fn | |
| self.args = args | |
| self.kwargs = kwargs | |
| def fn(x: int, y: str) -> int: | |
| return 1 |
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 | |
| class Foo[**P, T]: ... | |
| reveal_type(Foo[Any, int]) |
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
| def foo(variants: dict[str, dict[str, str]] = None) -> str: | |
| return "hello" |
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 Self, Protocol | |
| class Comparable(Protocol): | |
| def __lt__(self, other: Self, /) -> bool: | |
| ... | |
| def funny(c: bool) -> Comparable: | |
| if c: | |
| return ('', '') | |
| return ('', None) |
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 datetime import date, datetime, timedelta | |
| from typing_extensions import Any, Generic, TypeVar | |
| _AnyDateT = TypeVar("_AnyDateT", date, datetime) | |
| _DateT_co = TypeVar("_DateT_co", bound=date, covariant=True) | |
| class datetime64(Generic[_DateT_co]): | |
| def __sub__(self: datetime64[_AnyDateT], other: _AnyDateT, /) -> timedelta: ... # type: ignore[empty-body] | |
| def repro(d: datetime64[Any]): |
NewerOlder