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
| age: int = 25 | |
| nom: str = "Mehdi" | |
| moyenne: float = 15.5 | |
| age = "vingt-cinq" | |
| nom = 42 | |
| moyenne = "excellent" |
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 func_with_kw_only(x: int, *, y: int = 0): | |
| return x + y | |
| def func_with_pos_only(x: int, y: int, /): | |
| return x + y | |
| func_with_kw_only(1) # OK | |
| func_with_kw_only(1, y=2) # OK | |
| func_with_kw_only(1, 2) # error: Too many positional arguments for "func_with_kw_only" [call-arg] |
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 collections.abc import Callable | |
| class Animal: ... | |
| class Dog(Animal): | |
| def bark(self) -> None: print("woof") | |
| class Cat(Animal): ... | |
| class Handler[T]: | |
| def __init__(self, cb: Callable[[T], None]) -> None: | |
| self.cb = cb |
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(a_type: type) -> None: | |
| reveal_type(a_type) # N: Revealed type is "builtins.type" | |
| class Sub(a_type): 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
| class Person(): | |
| def __init__(self, name: str, age: int, characteristics: type): | |
| self.name = name | |
| self.age = age | |
| self.characteristics = characteristics | |
| def foo(person: Person) -> None: | |
| reveal_type(person.characteristics) # N: Revealed type is "builtins.type" | |
| class Sub(person.characteristics): 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
| class Person(): | |
| def __init__(self, name: str, age: int, characteristics: type): | |
| self.name = name | |
| self.age = age | |
| self.characteristics = characteristics | |
| def foo(person: Person) -> None: | |
| reveal_type(person.characteristics) # N: Revealed type is "builtins.type" | |
| class Sub(person.characteristics): 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 Any | |
| class Person(): | |
| def __init__(self, name: str, age: int, characteristics: type): | |
| self.name = name | |
| self.age = age | |
| self.characteristics = characteristics | |
| def foo(person: Person) -> None: | |
| reveal_type(person.characteristics) # N: Revealed type is "builtins.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
| mypy somme.py |
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 Iterator | |
| def fib(n: int) -> Iterator[int]: | |
| a, b = 0, 1 | |
| while a < n: | |
| yield a | |
| a, b = b, a + b |
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 overload, Optional | |
| class A: | |
| pass | |
| class B: | |
| pass | |
| class C: | |
| pass |
NewerOlder