Skip to content

Commit

Permalink
python/plane-tickets: 2nd iteration - py3.11
Browse files Browse the repository at this point in the history
  • Loading branch information
vpayno committed Apr 5, 2024
1 parent 002a171 commit 3aad757
Show file tree
Hide file tree
Showing 4 changed files with 154 additions and 154 deletions.
2 changes: 1 addition & 1 deletion python/plane-tickets/.coverage.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" ?>
<coverage version="7.4.0" timestamp="1712287282377" lines-valid="38" lines-covered="38" line-rate="1" branches-valid="12" branches-covered="12" branch-rate="1" complexity="0">
<coverage version="7.4.0" timestamp="1712287513036" lines-valid="38" lines-covered="38" line-rate="1" branches-valid="12" branches-covered="12" branch-rate="1" complexity="0">
<!-- Generated by coverage.py: https://coverage.readthedocs.io/en/7.4.0 -->
<!-- Based on https://raw.githubusercontent.com/cobertura/web/master/htdocs/xml/coverage-04.dtd -->
<sources>
Expand Down
50 changes: 25 additions & 25 deletions python/plane-tickets/generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@

from typing import Any, Generator

type index_t = int # type: ignore[valid-type]
type quantity_t = int # type: ignore[valid-type]
IndexT = int
QuantityT = int

type letter_t = str # type: ignore[valid-type]
type letters_t = list[letter_t] # type: ignore[valid-type]
LetterT = str
LettersT = list[LetterT]

type row_t = int # type: ignore[valid-type]
type seat_t = str # type: ignore[valid-type]
type seats_t = list[seat_t] # type: ignore[valid-type]
RowT = int
SeatT = str
SeatsT = list[SeatT]

type name_t = str # type: ignore[valid-type]
type passengers_t = list[name_t] # type: ignore[valid-type]
type seat_assignments_t = dict[name_t, seat_t] # type: ignore[valid-type]
NameT = str
PassengersT = list[NameT]
SeatAssignmentsT = dict[NameT, SeatT]

type code_t = str # type: ignore[valid-type]
type flight_id_t = str # type: ignore[valid-type]
CodeT = str
FlightIdT = str


def generate_seat_letters(quantity: quantity_t) -> Generator[letter_t, Any, Any]:
def generate_seat_letters(quantity: QuantityT) -> Generator[LetterT, Any, Any]:
"""Generate a series of letters for airline seats.
:param quantity: int - total number of seat letters to be generated.
Expand All @@ -32,15 +32,15 @@ def generate_seat_letters(quantity: quantity_t) -> Generator[letter_t, Any, Any]
Example: A, B, C, D
"""

letters: letters_t = ["A", "B", "C", "D"]
letters: LettersT = ["A", "B", "C", "D"]

for pos in range(0, quantity):
index: index_t = pos % len(letters)
index: IndexT = pos % len(letters)

yield letters[index]


def generate_seats(quantity: quantity_t) -> Generator[seat_t, Any, Any]:
def generate_seats(quantity: QuantityT) -> Generator[SeatT, Any, Any]:
"""Generate a series of identifiers for airline seats.
:param quantity: int - total number of seats to be generated.
Expand All @@ -56,11 +56,11 @@ def generate_seats(quantity: quantity_t) -> Generator[seat_t, Any, Any]:
Example: 3C, 3D, 4A, 4B
"""

letter: Generator[letter_t, Any, Any] = generate_seat_letters(quantity)
row: row_t = 0
letter: Generator[LetterT, Any, Any] = generate_seat_letters(quantity)
row: RowT = 0

for _ in range(1, quantity + 1):
seat: seat_t = next(letter)
seat: SeatT = next(letter)

if seat == "A":
row += 1
Expand All @@ -71,7 +71,7 @@ def generate_seats(quantity: quantity_t) -> Generator[seat_t, Any, Any]:
yield f"{row}{seat}"


def assign_seats(passengers: passengers_t) -> seat_assignments_t:
def assign_seats(passengers: PassengersT) -> SeatAssignmentsT:
"""Assign seats to passengers.
:param passengers: list[str] - a list of strings containing names of passengers.
Expand All @@ -80,8 +80,8 @@ def assign_seats(passengers: passengers_t) -> seat_assignments_t:
Example output: {"Adele": "1A", "Björk": "1B"}
"""

seat_assignments: seat_assignments_t = {}
seat: Generator[seat_t, Any, Any] = generate_seats(len(passengers))
seat_assignments: SeatAssignmentsT = {}
seat: Generator[SeatT, Any, Any] = generate_seats(len(passengers))

for passenger in passengers:
seat_assignments[passenger] = next(seat)
Expand All @@ -90,8 +90,8 @@ def assign_seats(passengers: passengers_t) -> seat_assignments_t:


def generate_codes(
seat_numbers: seats_t, flight_id: flight_id_t
) -> Generator[code_t, Any, Any]:
seat_numbers: SeatsT, flight_id: FlightIdT
) -> Generator[CodeT, Any, Any]:
"""Generate codes for a ticket.
:param seat_numbers: list[str] - list of seat numbers.
Expand All @@ -100,6 +100,6 @@ def generate_codes(
"""

for seat in seat_numbers:
code: code_t = f"{seat}{flight_id}"
code: CodeT = f"{seat}{flight_id}"

yield f"{code:012}"
50 changes: 25 additions & 25 deletions python/plane-tickets/generators.py,cover
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@

> from typing import Any, Generator

> type index_t = int # type: ignore[valid-type]
> type quantity_t = int # type: ignore[valid-type]
> IndexT = int
> QuantityT = int

> type letter_t = str # type: ignore[valid-type]
> type letters_t = list[letter_t] # type: ignore[valid-type]
> LetterT = str
> LettersT = list[LetterT]

> type row_t = int # type: ignore[valid-type]
> type seat_t = str # type: ignore[valid-type]
> type seats_t = list[seat_t] # type: ignore[valid-type]
> RowT = int
> SeatT = str
> SeatsT = list[SeatT]

> type name_t = str # type: ignore[valid-type]
> type passengers_t = list[name_t] # type: ignore[valid-type]
> type seat_assignments_t = dict[name_t, seat_t] # type: ignore[valid-type]
> NameT = str
> PassengersT = list[NameT]
> SeatAssignmentsT = dict[NameT, SeatT]

> type code_t = str # type: ignore[valid-type]
> type flight_id_t = str # type: ignore[valid-type]
> CodeT = str
> FlightIdT = str


> def generate_seat_letters(quantity: quantity_t) -> Generator[letter_t, Any, Any]:
> def generate_seat_letters(quantity: QuantityT) -> Generator[LetterT, Any, Any]:
> """Generate a series of letters for airline seats.

> :param quantity: int - total number of seat letters to be generated.
Expand All @@ -32,15 +32,15 @@
> Example: A, B, C, D
> """

> letters: letters_t = ["A", "B", "C", "D"]
> letters: LettersT = ["A", "B", "C", "D"]

> for pos in range(0, quantity):
> index: index_t = pos % len(letters)
> index: IndexT = pos % len(letters)

> yield letters[index]


> def generate_seats(quantity: quantity_t) -> Generator[seat_t, Any, Any]:
> def generate_seats(quantity: QuantityT) -> Generator[SeatT, Any, Any]:
> """Generate a series of identifiers for airline seats.

> :param quantity: int - total number of seats to be generated.
Expand All @@ -56,11 +56,11 @@
> Example: 3C, 3D, 4A, 4B
> """

> letter: Generator[letter_t, Any, Any] = generate_seat_letters(quantity)
> row: row_t = 0
> letter: Generator[LetterT, Any, Any] = generate_seat_letters(quantity)
> row: RowT = 0

> for _ in range(1, quantity + 1):
> seat: seat_t = next(letter)
> seat: SeatT = next(letter)

> if seat == "A":
> row += 1
Expand All @@ -71,7 +71,7 @@
> yield f"{row}{seat}"


> def assign_seats(passengers: passengers_t) -> seat_assignments_t:
> def assign_seats(passengers: PassengersT) -> SeatAssignmentsT:
> """Assign seats to passengers.

> :param passengers: list[str] - a list of strings containing names of passengers.
Expand All @@ -80,8 +80,8 @@
> Example output: {"Adele": "1A", "Björk": "1B"}
> """

> seat_assignments: seat_assignments_t = {}
> seat: Generator[seat_t, Any, Any] = generate_seats(len(passengers))
> seat_assignments: SeatAssignmentsT = {}
> seat: Generator[SeatT, Any, Any] = generate_seats(len(passengers))

> for passenger in passengers:
> seat_assignments[passenger] = next(seat)
Expand All @@ -90,8 +90,8 @@


> def generate_codes(
> seat_numbers: seats_t, flight_id: flight_id_t
> ) -> Generator[code_t, Any, Any]:
> seat_numbers: SeatsT, flight_id: FlightIdT
> ) -> Generator[CodeT, Any, Any]:
> """Generate codes for a ticket.

> :param seat_numbers: list[str] - list of seat numbers.
Expand All @@ -100,6 +100,6 @@
> """

> for seat in seat_numbers:
> code: code_t = f"{seat}{flight_id}"
> code: CodeT = f"{seat}{flight_id}"

> yield f"{code:012}"
Loading

0 comments on commit 3aad757

Please sign in to comment.