Skip to content

Commit

Permalink
docs: fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-ong committed Dec 29, 2023
1 parent 54148e6 commit 65334d3
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 13 deletions.
7 changes: 0 additions & 7 deletions day01/day1a.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,12 @@ def get_first_last(line: str) -> tuple[str, str]:
It can be the same character.
Args:
----
line (str): string to parse
Raises:
------
ValueError: When there are no numbers in the string
Returns:
-------
tuple[str, str]: first char, last char
"""
first: Optional[str] = None
Expand All @@ -41,11 +38,9 @@ def get_input(input_file: str) -> list[str]:
"""Grabs list of lines to parse from input file.
Args:
----
input_file (str): input file's name
Returns:
-------
list[str]: list of lines to parse
"""
with open(input_file, "r", encoding="utf8") as file:
Expand All @@ -56,11 +51,9 @@ def part1(lines: list[str]) -> int:
"""Runs day1/part1 of adventofcode2023.
Args:
----
lines (list[str]): list of lines to parse
Returns:
-------
int: sum of results for each line.
"""
total = 0
Expand Down
2 changes: 1 addition & 1 deletion day02/day2.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def get_games(input_file: str) -> list[Game]:
input_file (str): input file name
Returns:
list[Game]: list of ``Game``s
list[Game]: list of Games
"""
with open(input_file, "r", encoding="utf8") as file:
games: list[Game] = []
Expand Down
4 changes: 2 additions & 2 deletions day14/day14.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ def correct_side(self) -> "World":


def naive_score(world_rows: list[str]) -> int:
"""Returns score assuming west is pointing left.
r"""Returns score assuming west is pointing left.
For each row, a round boulder ``O``'s score is
``num_rows`` minus its ``index``(higher weight to the left.)
``num_rows`` minus its ``index`` (higher weight to the left.)
"""
num_rows = len(world_rows)
score = 0
Expand Down
2 changes: 1 addition & 1 deletion day15/lib/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def __str__(self) -> str:

@dataclass
class Box:
"""Box can contain a variety of ``Lens``es."""
r"""Box can contain a variety of ``Lens``\es."""

id: int = 0
contents: list[Lens] = field(default_factory=list)
Expand Down
1 change: 1 addition & 0 deletions day16/lib/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""library modules for day16."""
27 changes: 25 additions & 2 deletions day16/lib/cells.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
"""Cell classes
"""
"""Cell classes."""
from abc import ABC, abstractmethod

from day16.lib.direction import Direction
from day16.lib.laser import Laser


class Cell(ABC):
"""Abstract cell class."""

contents: str

@staticmethod
def construct(contents: str) -> "Cell":
"""Construct proper cell from given contents."""
if contents == ".":
return DotCell()
elif contents == "|":
Expand All @@ -25,23 +27,32 @@ def construct(contents: str) -> "Cell":

@abstractmethod
def next_lasers(self, laser: Laser) -> list[Laser]:
"""Return next lasers given a laser entering this cell."""
raise AssertionError("Not supported", laser)


class DotCell(Cell):
"""A dot cell."""

def __init__(self) -> None:
"""Sets our contents to ``.``."""
self.contents = "."

def next_lasers(self, laser: Laser) -> list[Laser]:
"""Lasers pass directly through this tile."""
row, col = laser.direction.offset(laser.row, laser.col)
return [Laser(row, col, laser.direction)]


class DashCell(Cell):
"""A ``-`` cell."""

def __init__(self) -> None:
"""Sets our contents to ``-``."""
self.contents = "-"

def next_lasers(self, laser: Laser) -> list[Laser]:
"""Lasers must end up going east/west after passing through this cell."""
if laser.direction in [Direction.EAST, Direction.WEST]:
row, col = laser.direction.offset(laser.row, laser.col)
return [Laser(row, col, laser.direction)]
Expand All @@ -55,10 +66,14 @@ def next_lasers(self, laser: Laser) -> list[Laser]:


class PipeCell(Cell):
"""A ``|`` cell."""

def __init__(self) -> None:
"""Sets our contents to ``|``."""
self.contents = "|"

def next_lasers(self, laser: Laser) -> list[Laser]:
"""Lasers must end up going north/south after passing through this cell."""
if laser.direction in [Direction.NORTH, Direction.SOUTH]:
row, col = laser.direction.offset(laser.row, laser.col)
return [Laser(row, col, laser.direction)]
Expand All @@ -72,10 +87,14 @@ def next_lasers(self, laser: Laser) -> list[Laser]:


class ForwardSlashCell(Cell):
"""A ``/`` cell."""

def __init__(self) -> None:
"""Sets our contents to ``/``."""
self.contents = "/"

def next_lasers(self, laser: Laser) -> list[Laser]:
"""Lasers go diagonal mode."""
row, col = laser.row, laser.col
if laser.direction == Direction.EAST:
return [Laser(row - 1, col, Direction.NORTH)]
Expand All @@ -89,10 +108,14 @@ def next_lasers(self, laser: Laser) -> list[Laser]:


class BackSlashCell(Cell):
r"""A ``\`` cell."""

def __init__(self) -> None:
r"""Sets our contents to ``\``."""
self.contents = "\\"

def next_lasers(self, laser: Laser) -> list[Laser]:
"""Lasers go diagonal mode."""
row, col = laser.row, laser.col
if laser.direction == Direction.EAST:
return [Laser(row + 1, col, Direction.SOUTH)]
Expand Down
6 changes: 6 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
"sphinx.ext.viewcode",
]

suppress_warnings = [
# This is here to prevent:
# "WARNING: more than one target found for cross-reference"
"ref.python",
]

templates_path = ["_templates"]
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]

Expand Down

0 comments on commit 65334d3

Please sign in to comment.