Skip to content

Commit

Permalink
Combine 3.11 and 3.12 code in the same file
Browse files Browse the repository at this point in the history
  • Loading branch information
gahjelle committed Sep 20, 2023
1 parent 46e0103 commit 5e74e07
Show file tree
Hide file tree
Showing 12 changed files with 88 additions and 64 deletions.
13 changes: 12 additions & 1 deletion python-312/typing/alias.py
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)
7 changes: 0 additions & 7 deletions python-312/typing/alias_311.py

This file was deleted.

13 changes: 12 additions & 1 deletion python-312/typing/concatenation.py
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
7 changes: 0 additions & 7 deletions python-312/typing/concatenation_311.py

This file was deleted.

14 changes: 13 additions & 1 deletion python-312/typing/deck.py
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))
8 changes: 0 additions & 8 deletions python-312/typing/deck_311.py

This file was deleted.

21 changes: 20 additions & 1 deletion python-312/typing/generic_queue.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from collections import deque
from typing import Generic, TypeVar

T = TypeVar("T")

class Queue[T]:

class Queue(Generic[T]):
def __init__(self) -> None:
self.elements: deque[T] = deque()

Expand All @@ -10,3 +13,19 @@ def push(self, element: T) -> None:

def pop(self) -> T:
return self.elements.popleft()


# %% Python 3.12

# from collections import deque
#
#
# class Queue[T]:
# def __init__(self) -> None:
# self.elements: deque[T] = deque()
#
# def push(self, element: T) -> None:
# self.elements.append(element)
#
# def pop(self) -> T:
# return self.elements.popleft()
15 changes: 0 additions & 15 deletions python-312/typing/generic_queue_311.py

This file was deleted.

19 changes: 18 additions & 1 deletion python-312/typing/inspect_string.py
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
13 changes: 0 additions & 13 deletions python-312/typing/inspect_string_311.py

This file was deleted.

14 changes: 13 additions & 1 deletion python-312/typing/list_helpers.py
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)
8 changes: 0 additions & 8 deletions python-312/typing/list_helpers_311.py

This file was deleted.

0 comments on commit 5e74e07

Please sign in to comment.