-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Combine 3.11 and 3.12 code in the same file
- Loading branch information
Showing
12 changed files
with
88 additions
and
64 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,14 @@ | ||
type Ordered[T] = list[T] | tuple[T, ...] | ||
from typing import TypeAlias, TypeVar | ||
|
||
T = TypeVar("T") | ||
|
||
Ordered: TypeAlias = list[T] | tuple[T, ...] | ||
|
||
numbers: Ordered[int] = (1, 2, 3) | ||
|
||
|
||
# %% Python 3.12 | ||
|
||
# type Ordered[T] = list[T] | tuple[T, ...] | ||
# | ||
# numbers: Ordered[int] = (1, 2, 3) |
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,13 @@ | ||
def concatenate[T: (str, bytes)](first: T, second: T) -> T: | ||
from typing import TypeVar | ||
|
||
T = TypeVar("T", str, bytes) | ||
|
||
|
||
def concatenate(first: T, second: T) -> T: | ||
return first + second | ||
|
||
|
||
# %% Python 3.12 | ||
|
||
# def concatenate[T: (str, bytes)](first: T, second: T) -> T: | ||
# return first + second |
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,18 @@ | ||
import random | ||
from typing import TypeAlias | ||
|
||
CardDeck: TypeAlias = list[tuple[str, int]] | ||
|
||
type CardDeck = list[tuple[str, int]] | ||
|
||
def shuffle(deck: CardDeck) -> CardDeck: | ||
return random.sample(deck, k=len(deck)) | ||
|
||
|
||
# %% Python 3.12 | ||
|
||
# import random | ||
# | ||
# type CardDeck = list[tuple[str, int]] | ||
# | ||
# def shuffle(deck: CardDeck) -> CardDeck: | ||
# return random.sample(deck, k=len(deck)) |
This file was deleted.
Oops, something went wrong.
This file contains 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
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,25 @@ | ||
from typing import TypeVar | ||
|
||
S = TypeVar("S", bound=str) | ||
|
||
|
||
class Words(str): | ||
def __len__(self): | ||
return len(self.split()) | ||
|
||
|
||
def inspect[S: str](text: S) -> S: | ||
def inspect(text: S) -> S: | ||
print(f"'{text.upper()}' has length {len(text)}") | ||
return text | ||
|
||
|
||
# %% Python 3.12 | ||
|
||
# class Words(str): | ||
# def __len__(self): | ||
# return len(self.split()) | ||
# | ||
# | ||
# def inspect[S: str](text: S) -> S: | ||
# print(f"'{text.upper()}' has length {len(text)}") | ||
# return text |
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,15 @@ | ||
def push_and_pop[T](elements: list[T], element: T) -> T: | ||
from typing import TypeVar | ||
|
||
T = TypeVar("T") | ||
|
||
|
||
def push_and_pop(elements: list[T], element: T) -> T: | ||
elements.append(element) | ||
return elements.pop(0) | ||
|
||
|
||
# %% Python 3.12 | ||
|
||
# def push_and_pop[T](elements: list[T], element: T) -> T: | ||
# elements.append(element) | ||
# return elements.pop(0) |
This file was deleted.
Oops, something went wrong.