Skip to content

[Linting]: Lint practice stub files (2 / ?) #2789

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Nov 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions exercises/practice/book-store/.meta/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@
}


def _total(books):
volumes = Counter(books)
price = len(books) * PER_BOOK
def _total(basket):
volumes = Counter(basket)
price = len(basket) * PER_BOOK
for size in range(len(volumes), 1, -1):
group = volumes - Counter(k for k, _ in volumes.most_common(size))
group_books = sorted(group.elements())
price = min(price, PER_GROUP[size] + _total(group_books))
return price


def total(books):
if not books:
def total(basket):
if not basket:
return 0
return _total(sorted(books))
return _total(sorted(basket))
16 changes: 8 additions & 8 deletions exercises/practice/bowling/.meta/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,26 +59,26 @@ def next_throws(self, frame_idx):
def roll_bonus(self, pins):
tenth_frame = self.frames[-1]
if tenth_frame.is_open():
raise IndexError("cannot throw bonus with an open tenth frame")
raise IndexError('cannot throw bonus with an open tenth frame')

self.bonus_throws.append(pins)

# Check against invalid fill balls, e.g. [3, 10]
if (len(self.bonus_throws) == 2 and self.bonus_throws[0] != 10 and
sum(self.bonus_throws) > 10):
raise ValueError("invalid fill balls")
raise ValueError('invalid fill balls')

# Check if there are more bonuses than it should be
if tenth_frame.is_strike() and len(self.bonus_throws) > 2:
raise IndexError(
"wrong number of fill balls when the tenth frame is a strike")
'wrong number of fill balls when the tenth frame is a strike')
elif tenth_frame.is_spare() and len(self.bonus_throws) > 1:
raise IndexError(
"wrong number of fill balls when the tenth frame is a spare")
'wrong number of fill balls when the tenth frame is a spare')

def roll(self, pins):
if not 0 <= pins <= 10:
raise ValueError("invalid pins")
raise ValueError('invalid pins')
elif self.current_frame_idx == MAX_FRAME:
self.roll_bonus(pins)
else:
Expand All @@ -88,12 +88,12 @@ def roll(self, pins):

def score(self):
if self.current_frame_idx < MAX_FRAME:
raise IndexError("frame less than 10")
raise IndexError('frame less than 10')
if self.frames[-1].is_spare() and len(self.bonus_throws) != 1:
raise IndexError(
"one bonus must be rolled when the tenth frame is spare")
'one bonus must be rolled when the tenth frame is spare')
if self.frames[-1].is_strike() and len(self.bonus_throws) != 2:
raise IndexError(
"two bonuses must be rolled when the tenth frame is strike")
'two bonuses must be rolled when the tenth frame is strike')
return sum(frame.score(self.next_throws(frame.idx))
for frame in self.frames)
4 changes: 2 additions & 2 deletions exercises/practice/change/.meta/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ def find_fewest_coins(coins, target):
if target < 0:
raise ValueError("target can't be negative")
min_coins_required = [1e9] * (target + 1)
last_coin = [0]*(target + 1)
last_coin = [0] * (target + 1)
min_coins_required[0] = 0
last_coin[0] = -1
for change in range(1, target + 1):
Expand All @@ -19,7 +19,7 @@ def find_fewest_coins(coins, target):
else:
last_coin_value = target
array = []
while(last_coin[last_coin_value] != -1):
while last_coin[last_coin_value] != -1:
array.append(last_coin_value-last_coin[last_coin_value])
last_coin_value = last_coin[last_coin_value]
return array
4 changes: 2 additions & 2 deletions exercises/practice/circular-buffer/.meta/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def clear(self):

def write(self, data):
if all(self.buffer):
raise BufferFullException("Circular buffer is full")
raise BufferFullException('Circular buffer is full')
self._update_buffer(data)
self.write_point = (self.write_point + 1) % len(self.buffer)

Expand All @@ -49,7 +49,7 @@ def overwrite(self, data):

def read(self):
if not any(self.buffer):
raise BufferEmptyException("Circular buffer is empty")
raise BufferEmptyException('Circular buffer is empty')
data = chr(self.buffer[self.read_point])
self.buffer[self.read_point] = 0
self.read_point = (self.read_point + 1) % len(self.buffer)
Expand Down
4 changes: 2 additions & 2 deletions exercises/practice/clock/.meta/example.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
class Clock:
'Clock that displays 24 hour clock that rollsover properly'
"""Clock that displays 24 hour clock that rollsover properly"""

def __init__(self, hour, minute):
self.hour = hour
self.minute = minute
self.cleanup()

def __repr__(self):
return "{:02d}:{:02d}".format(self.hour, self.minute)
return '{:02d}:{:02d}'.format(self.hour, self.minute)

def __eq__(self, other):
return repr(self) == repr(other)
Expand Down
18 changes: 9 additions & 9 deletions exercises/practice/collatz-conjecture/.meta/example.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
def steps(n):
if n <= 0:
raise ValueError("Only positive numbers are allowed")
def steps(number):
if number <= 0:
raise ValueError('Only positive numbers are allowed')

step_count = 0
while n > 1:
if is_odd(n):
n = n * 3 + 1
while number > 1:
if is_odd(number):
number = number * 3 + 1
else:
n = n / 2
number = number / 2
step_count += 1

return step_count


def is_odd(n):
return n % 2 == 1
def is_odd(number):
return number % 2 == 1
22 changes: 11 additions & 11 deletions exercises/practice/complex-numbers/.meta/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ def __init__(self, real=0, imaginary=0):
self.imaginary = imaginary

def __eq__(self, other):
if not type(other) == ComplexNumber:
if not isinstance(other, ComplexNumber):
other = ComplexNumber(other)
return self.real == other.real and self.imaginary == other.imaginary

def __add__(self, other):

if not type(other) is ComplexNumber:
if not isinstance(other, ComplexNumber):
other = ComplexNumber(other)

real_part = self.real + other.real
Expand All @@ -22,7 +22,7 @@ def __add__(self, other):

def __radd__(self, other):

if not type(other) is ComplexNumber:
if not isinstance(other, ComplexNumber):
other = ComplexNumber(other)

real_part = self.real + other.real
Expand All @@ -31,57 +31,57 @@ def __radd__(self, other):
return ComplexNumber(real_part, imaginary_part)

def __mul__(self, other):
if not type(other) == ComplexNumber:
if not isinstance(other, ComplexNumber):
other = ComplexNumber(other)

real_part = self.real * other.real - self.imaginary * other.imaginary
imaginary_part = self.real * other.imaginary + self.imaginary * other.real
return ComplexNumber(real_part, imaginary_part)

def __rmul__(self, other):
if not type(other) == ComplexNumber:
if not isinstance(other, ComplexNumber):
other = ComplexNumber(other)

real_part = self.real * other.real - self.imaginary * other.imaginary
imaginary_part = self.real * other.imaginary + self.imaginary * other.real
return ComplexNumber(real_part, imaginary_part)

def __sub__(self, other):
if not type(other) == ComplexNumber:
if not isinstance(other, ComplexNumber):
other = ComplexNumber(other)
real_part = self.real - other.real
imaginary_part = self.imaginary - other.imaginary
return ComplexNumber(real_part, imaginary_part)

def __rsub__(self, other):
if not type(other) == ComplexNumber:
if not isinstance(other, ComplexNumber):
other = ComplexNumber(other)

real_part = other.real - self.real
imaginary_part = other.imaginary - self.imaginary
return ComplexNumber(real_part, imaginary_part)

def __truediv__(self, other):
if not type(other) == ComplexNumber:
if not isinstance(other, ComplexNumber):
other = ComplexNumber(other)

conjugation = other.conjugate()
denominator_all = other * conjugation
denominator = denominator_all.real
numerator = self * conjugation

return ComplexNumber((numerator.real/denominator), (numerator.imaginary/denominator))
return ComplexNumber((numerator.real / denominator), (numerator.imaginary / denominator))

def __rtruediv__(self, other):
if not type(other) == ComplexNumber:
if not isinstance(other, ComplexNumber):
other = ComplexNumber(other)

conjugation = self.conjugate()
denominator_all = self * conjugation
denominator = float(denominator_all.real)
numerator = other * conjugation

return ComplexNumber((numerator.real/denominator), (numerator.imaginary/denominator))
return ComplexNumber((numerator.real / denominator), (numerator.imaginary / denominator))

def __abs__(self):
square_sum = self.real * self.real + self.imaginary * self.imaginary
Expand Down
66 changes: 35 additions & 31 deletions exercises/practice/connect/.meta/example.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@

class ConnectGame:

directions = [(0, 1), (0, -1), (1, 0), (-1, 0), (1, -1), (-1, 1)]
white = "O"
black = "X"
none = ""
DIRECTIONS = [(0, 1), (0, -1), (1, 0), (-1, 0), (1, -1), (-1, 1)]
WHITE = 'O'
BLACK = 'X'

def __init__(self, lines):
self.board = ConnectGame.make_board(lines)
Expand All @@ -14,49 +13,54 @@ def __init__(self, lines):
self.height = len(self.board)
assert self.width > 0 and self.height > 0

for l in self.board:
assert len(l) == self.width
for line in self.board:
assert len(line) == self.width

def valid(self, x, y):
return 0 <= x < self.width and 0 <= y < self.height
def valid(self, width, height):
return 0 <= width < self.width and 0 <= height < self.height

@staticmethod
def make_board(lines):
return ["".join(l.split()) for l in lines.splitlines()]
return [''.join(cur_line.split()) for cur_line in lines.splitlines()]

def player_reach_dest(self, player, x, y):
if player == self.black:
return x == self.width - 1
if player == self.white:
return y == self.height - 1
def player_reach_dest(self, player, width, height):
if player == self.BLACK:
return width == self.width - 1
if player == self.WHITE:
return height == self.height - 1
return None

def walk_board(self, player, x, y, visited=[]):
if (x, y) in visited:
def walk_board(self, player, width, height, visited=None):
if not visited:
visited = []
if (width, height) in visited:
return False

if (not self.valid(x, y)) or self.board[y][x] != player:
if (not self.valid(width, height)) or self.board[height][width] != player:
return False

if self.player_reach_dest(player, x, y):
if self.player_reach_dest(player, width, height):
return True

for d in self.directions:
if self.walk_board(player, x + d[0], y + d[1], visited + [(x, y)]):
for vector in self.DIRECTIONS:
if self.walk_board(player, width + vector[0], height + vector[1], visited + [(width, height)]):
return True
return None

def check_player_is_winner(self, player):
if player == self.black:
for y in range(self.height):
if self.walk_board(player, 0, y):
if player == self.BLACK:
for height in range(self.height):
if self.walk_board(player, 0, height):
return True
if player == self.white:
for x in range(self.width):
if self.walk_board(player, x, 0):
if player == self.WHITE:
for width in range(self.width):
if self.walk_board(player, width, 0):
return True
return None

def get_winner(self):
if self.check_player_is_winner(self.black):
return self.black
if self.check_player_is_winner(self.white):
return self.white
return self.none
if self.check_player_is_winner(self.BLACK):
return self.BLACK
if self.check_player_is_winner(self.WHITE):
return self.WHITE
return ''
7 changes: 1 addition & 6 deletions exercises/practice/crypto-square/.meta/example.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
from math import ceil, sqrt
import sys

if sys.version_info[0] == 2:
from itertools import izip_longest as zip_longest
else:
from itertools import zip_longest
from itertools import zip_longest


def cipher_text(plain_text):
Expand Down
Loading