Skip to content

Commit

Permalink
Code formatted with Ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
ABDreos authored and github-actions[bot] committed Mar 20, 2024
1 parent 4650f88 commit 9fa164d
Show file tree
Hide file tree
Showing 197 changed files with 2,043 additions and 1,833 deletions.
1 change: 0 additions & 1 deletion 2022/ab_testing/with_tracking/feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class Config:


def read_config() -> Config:

api_key = os.getenv("GROWTHBOOK_KEY") or ""
response = requests.get(
f"https://cdn.growthbook.io/api/features/{api_key}", timeout=5
Expand Down
3 changes: 1 addition & 2 deletions 2022/adapter/adapter/config_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@


class Config(Protocol):
def get(self, key: str) -> Any | None:
...
def get(self, key: str) -> Any | None: ...
3 changes: 1 addition & 2 deletions 2022/adapter/adapter_partial/config_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@


class Config(Protocol):
def get(self, key: str, default: Any = None) -> Any | None:
...
def get(self, key: str, default: Any = None) -> Any | None: ...
1 change: 0 additions & 1 deletion 2022/adapter/adapter_partial/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@


def main() -> None:

with open("config.json", encoding="utf8") as file:
config = json.load(file)
with open("config.xml", encoding="utf8") as file:
Expand Down
9 changes: 3 additions & 6 deletions 2022/async/after-1/iot/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,11 @@ def generate_id(length: int = 8):


class Device(Protocol):
async def connect(self) -> None:
...
async def connect(self) -> None: ...

async def disconnect(self) -> None:
...
async def disconnect(self) -> None: ...

async def send_message(self, message_type: MessageType, data: str = "") -> None:
...
async def send_message(self, message_type: MessageType, data: str = "") -> None: ...


class IOTService:
Expand Down
9 changes: 3 additions & 6 deletions 2022/async/after-2/iot/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,11 @@ def generate_id(length: int = 8):


class Device(Protocol):
async def connect(self) -> None:
...
async def connect(self) -> None: ...

async def disconnect(self) -> None:
...
async def disconnect(self) -> None: ...

async def send_message(self, message_type: MessageType, data: str = "") -> None:
...
async def send_message(self, message_type: MessageType, data: str = "") -> None: ...


class IOTService:
Expand Down
9 changes: 3 additions & 6 deletions 2022/async/before/iot/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,11 @@ def generate_id(length: int = 8):


class Device(Protocol):
def connect(self) -> None:
...
def connect(self) -> None: ...

def disconnect(self) -> None:
...
def disconnect(self) -> None: ...

def send_message(self, message_type: MessageType, data: str) -> None:
...
def send_message(self, message_type: MessageType, data: str) -> None: ...


class IOTService:
Expand Down
1 change: 0 additions & 1 deletion 2022/asyncio_2/asyncio_gather.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ async def get_random_pokemon_name() -> str:


async def main() -> None:

# synchronous call
time_before = perf_counter()
for _ in range(20):
Expand Down
1 change: 0 additions & 1 deletion 2022/asyncio_2/asyncio_iter.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ async def next_pokemon(total: int) -> AsyncIterable[str]:


async def main():

# retrieve the next 10 pokemon names
async for name in next_pokemon(10):
print(name)
Expand Down
1 change: 0 additions & 1 deletion 2022/asyncio_2/sync_to_async_before.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ def send_request(url: str) -> int:


async def main() -> None:

status_code = send_request("https://www.arjancodes.com")
print(f"Got HTTP response with status {status_code}")

Expand Down
1 change: 0 additions & 1 deletion 2022/asyncio_2/sync_to_async_correct.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ async def send_async_request(url: str) -> int:


async def main() -> None:

status_code, _ = await asyncio.gather(
send_async_request("https://www.arjancodes.com"), counter()
)
Expand Down
1 change: 0 additions & 1 deletion 2022/bridge_pattern/with_abc/stream/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

@dataclass
class StreamingService(ABC):

devices: list[Buffer] = field(default_factory=list)

def add_device(self, device: Buffer) -> None:
Expand Down
9 changes: 3 additions & 6 deletions 2022/bridge_pattern/with_function/stream/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@


class StreamingService(Protocol):
def start_stream(self) -> str:
...
def start_stream(self) -> str: ...

def fill_buffer(self, stream_reference: str) -> None:
...
def fill_buffer(self, stream_reference: str) -> None: ...

def stop_stream(self, stream_reference: str) -> None:
...
def stop_stream(self, stream_reference: str) -> None: ...
1 change: 0 additions & 1 deletion 2022/bridge_pattern/with_function/stream/twitch_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

@dataclass
class TwitchStreamingService:

buffer: Buffer

def start_stream(self) -> str:
Expand Down
1 change: 0 additions & 1 deletion 2022/bridge_pattern/with_function/stream/youtube_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

@dataclass
class YouTubeStreamingService:

buffer: Buffer

def start_stream(self) -> str:
Expand Down
3 changes: 1 addition & 2 deletions 2022/bridge_pattern/with_protocol/stream/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@


class StreamingDevice(Protocol):
def get_buffer_data(self) -> BufferData:
...
def get_buffer_data(self) -> BufferData: ...
9 changes: 3 additions & 6 deletions 2022/bridge_pattern/with_protocol/stream/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@


class StreamingService(Protocol):
def start_stream(self) -> str:
...
def start_stream(self) -> str: ...

def fill_buffer(self, stream_reference: str) -> None:
...
def fill_buffer(self, stream_reference: str) -> None: ...

def stop_stream(self, stream_reference: str) -> None:
...
def stop_stream(self, stream_reference: str) -> None: ...
1 change: 0 additions & 1 deletion 2022/bridge_pattern/with_protocol/stream/twitch_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

@dataclass
class TwitchStreamingService:

device: StreamingDevice

def start_stream(self) -> str:
Expand Down
1 change: 0 additions & 1 deletion 2022/bridge_pattern/with_protocol/stream/youtube_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

@dataclass
class YouTubeStreamingService:

device: StreamingDevice

def start_stream(self) -> str:
Expand Down
1 change: 1 addition & 0 deletions 2022/cicd/functions/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# Define an internal Flask app
app = Flask("internal")


# Define the internal paths, idiomatic Flask definition
@app.route("/channels/<string:channel_id>", methods=["GET", "POST"])
def channel(channel_id: str):
Expand Down
1 change: 0 additions & 1 deletion 2022/code_roast/after/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@


def main() -> None:

# read the configuration settings from a JSON file
config = read_config("./config.json")

Expand Down
1 change: 0 additions & 1 deletion 2022/code_roast/after/scrape/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ def fetch_terms_from_pubid(target: pd.DataFrame, scraper: Scraper) -> pd.DataFra


def fetch_terms_from_pdf_files(config: ScrapeConfig) -> pd.DataFrame:

search_terms = [
path.join(config.paper_folder, file)
for file in listdir(config.paper_folder)
Expand Down
3 changes: 1 addition & 2 deletions 2022/code_roast/after/scrape/scraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ class ScrapeResult:


class Scraper(Protocol):
def scrape(self, search_text: str) -> ScrapeResult:
...
def scrape(self, search_text: str) -> ScrapeResult: ...
1 change: 0 additions & 1 deletion 2022/code_roast_battleship/after.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ def play_game(player_count: int, board: BattleshipBoard) -> None:
won_game = False

while total_guesses < GUESSES_COUNT * player_count:

# determine the current player and the remaining guesses
current_player = (total_guesses % player_count) + 1
remaining_guesses = GUESSES_COUNT - total_guesses // player_count
Expand Down
2 changes: 1 addition & 1 deletion 2022/code_roast_rpsls/before/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ class Entity(Enum):
LIZARD = auto()

def __repr__(self) -> str:
return f"{self.name} : {self.value}"
return f"{self.name} : {self.value}"
60 changes: 31 additions & 29 deletions 2022/code_roast_rpsls/before/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,37 @@
from rules import Rules
from entity import Entity


class Game:
"""Game class
"""
"""Game class"""

def __init__(self, user: str, max_round: int = 5) -> None:
print("Rock paper scissor spock and lizard...\n Welcome to the game.")
print("Rules are simple...")
print("Scissors decapitate Lizard, Scissors cuts paper, paper covers rock, rock crushes lizard, lizard poisons Spock, Spock smashes scissors, scissors decapitates lizard, lizard eats paper, paper disproves Spock, Spock vaporizes rock, and as it always has, rock crushes scissors.")
print(
"Scissors decapitate Lizard, Scissors cuts paper, paper covers rock, rock crushes lizard, lizard poisons Spock, Spock smashes scissors, scissors decapitates lizard, lizard eats paper, paper disproves Spock, Spock vaporizes rock, and as it always has, rock crushes scissors."
)
print("To begin press [Enter]")
_ = input()

self.scoreboard = Scoreboard()
self.max_round = max_round
self.entities = Entity
self.rules = Rules()
self.user: str = user
self.cpu: str = "cpu"

# register players in scoreboard
self.scoreboard.register_player(self.user)
self.scoreboard.register_player(self.cpu)



def display_entity_to_select(self) -> None:
"""Displays the user choices
"""
choices_text = ", ".join(f"({entity.value} for {entity.name})" for entity in self.entities)
print(f"Select {choices_text}:", end='\t')

"""Displays the user choices"""
choices_text = ", ".join(
f"({entity.value} for {entity.name})" for entity in self.entities
)
print(f"Select {choices_text}:", end="\t")

def get_user_input(self) -> Entity:
"""Takes user inputs and selects the entities
Expand All @@ -42,14 +45,14 @@ def get_user_input(self) -> Entity:
try:
self.display_entity_to_select()
choice = int(input())

if choice not in available_choices:
print("Please select from available choices")
else:
return self.entities(choice)
except ValueError:
print("You entered something other than a number")

def get_cpu_input(self) -> Entity:
"""Selects a random entity
Expand All @@ -58,7 +61,7 @@ def get_cpu_input(self) -> Entity:
"""
cpu_choice = random.randint(1, len(self.entities))
return self.entities(cpu_choice)

def display_current_round(self, user_entity: Entity, cpu_entity: Entity) -> None:
"""Displays current round
Expand All @@ -68,13 +71,14 @@ def display_current_round(self, user_entity: Entity, cpu_entity: Entity) -> None
"""
print(f"{self.user} ({user_entity.name}) x {self.cpu} ({cpu_entity.name})")
print("....")

def display_tie(self) -> None:
"""Display tie message
"""
"""Display tie message"""
print(f"It's a tie..")

def display_round_winner(self, winner_name: str, winner_entity: Entity, message: str) -> None:

def display_round_winner(
self, winner_name: str, winner_entity: Entity, message: str
) -> None:
"""Display the winner of the round
Args:
Expand All @@ -83,13 +87,12 @@ def display_round_winner(self, winner_name: str, winner_entity: Entity, message:
message (str): Reason for wins
"""
print(f"{winner_name} ({winner_entity.name}) wins the round as {message}")

def do_turn(self) -> None:
"""Function to continue the rounds
"""
"""Function to continue the rounds"""
user_entity = self.get_user_input()
cpu_entity = self.get_cpu_input()

self.display_current_round(user_entity, cpu_entity)
if cpu_entity == user_entity:
self.display_tie()
Expand All @@ -102,19 +105,18 @@ def do_turn(self) -> None:
else:
self.display_round_winner(self.cpu, cpu_entity, message)
self.scoreboard.points[self.cpu] += 1

@staticmethod
def get_user_name() -> str:
"""Static method to get user name as input
Returns:
str: Name enterd by user
"""
print("Please enter your name:", end='\t')
print("Please enter your name:", end="\t")
return str(input().strip())



def play(self):
for i in range(self.max_round):
self.do_turn()
self.scoreboard.display_scores()
self.scoreboard.display_scores()
8 changes: 4 additions & 4 deletions 2022/code_roast_rpsls/before/main.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from game import Game


def main() -> None:
"""Main function to start the game
"""
"""Main function to start the game"""
user_name = Game.get_user_name()
game = Game(user_name)
game.play()

if __name__ == '__main__':

if __name__ == "__main__":
main()

Loading

0 comments on commit 9fa164d

Please sign in to comment.