Skip to content

Commit 16e95c9

Browse files
committed
ruff 설정 변경 및 코드 포매팅
1 parent 4bfee38 commit 16e95c9

File tree

70 files changed

+466
-461
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+466
-461
lines changed

dfs.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
graph = {
1+
graph: dict[int, list[int]] = {
22
1: [2, 3, 4],
33
2: [5],
44
3: [5],
@@ -9,7 +9,9 @@
99
}
1010

1111

12-
def recursive_dfs(v: int, discovered: list[int] = []) -> list[int]:
12+
def recursive_dfs(v: int, discovered: list[int] | None = None) -> list[int]:
13+
if discovered is None:
14+
discovered = []
1315
discovered.append(v)
1416
for w in graph[v]:
1517
if w not in discovered:

pyproject.toml

+6
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,18 @@ ignore = [
4747
"E501", # line too long, handled by black
4848
"E711", # Comparison to None should be cond is None
4949
"E712", # Comparison to True should be cond is True or if cond:
50+
"E741", # ambiguous variable name
5051
"B008", # do not perform function calls in argument defaults
5152
"C901", # too complex
5253
"PLR0913", # too many arguments to function call
5354
"B028", # no-explicit-stacklevel
5455
]
5556

57+
[tool.ruff.lint.per-file-ignores]
58+
"**/test_solution.py" = [
59+
"PLR2004", # Magic value used in comparision
60+
]
61+
5662
[tool.ruff.format]
5763
quote-style = "single"
5864
indent-style = "space"

solutions/solution_0002/__init__.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ def __eq__(self, other):
1919
class Solution:
2020
def addTwoNumbers(
2121
self,
22-
l1: Optional[ListNode],
23-
l2: Optional[ListNode],
24-
) -> Optional[ListNode]:
22+
l1: ListNode | None,
23+
l2: ListNode | None,
24+
) -> ListNode | None:
2525
result = ListNode(0)
2626
current = result
2727
carry = 0

solutions/solution_0002/test_solution.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
from typing import List
2-
31
from . import ListNode, Solution
42

53

6-
def arrayToListNode(numbers: List[int]) -> ListNode | None:
4+
def arrayToListNode(numbers: list[int]) -> ListNode | None:
75
result = ListNode()
86
current = result
97
for number in numbers:

solutions/solution_0003/test_solution.py

+11-8
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,28 @@
22

33
from . import Solution
44

5-
CaseDict = TypedDict("CaseDict", {"input": str, "expected": int})
5+
6+
class CaseDict(TypedDict):
7+
input: str
8+
expected: int
69

710

811
test_cases: list[CaseDict] = [
912
{
10-
"input": 'abcabcbb',
11-
"expected": 3,
13+
'input': 'abcabcbb',
14+
'expected': 3,
1215
},
1316
{
14-
"input": 'bbbbb',
15-
"expected": 1,
17+
'input': 'bbbbb',
18+
'expected': 1,
1619
},
1720
{
18-
"input": 'pwwkew',
19-
"expected": 3,
21+
'input': 'pwwkew',
22+
'expected': 3,
2023
},
2124
]
2225

2326

2427
def test_solution():
2528
for test_case in test_cases:
26-
assert Solution().lengthOfLongestSubstring(test_case["input"]) == test_case["expected"]
29+
assert Solution().lengthOfLongestSubstring(test_case['input']) == test_case['expected']
+12-9
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
1-
from typing import List, TypedDict
1+
from typing import TypedDict
22

33
from . import Solution
44

5-
CaseDict = TypedDict('CaseDict', {'input': str, 'expected': List[str]})
65

6+
class CaseDict(TypedDict):
7+
input: str
8+
expected: list[str]
79

8-
test_cases: List[CaseDict] = [
9-
{"input": "babad", "expected": ["bab", "aba"]},
10-
{"input": "cbbd", "expected": ["bb"]},
11-
{"input": "a", "expected": ["a"]},
12-
{"input": "ac", "expected": ["a", "c"]},
10+
11+
test_cases: list[CaseDict] = [
12+
{'input': 'babad', 'expected': ['bab', 'aba']},
13+
{'input': 'cbbd', 'expected': ['bb']},
14+
{'input': 'a', 'expected': ['a']},
15+
{'input': 'ac', 'expected': ['a', 'c']},
1316
]
1417

1518

1619
def test_solution():
1720
for test_case in test_cases:
18-
actual_result = Solution().longestPalindrome(test_case["input"])
19-
assert actual_result in test_case["expected"]
21+
actual_result = Solution().longestPalindrome(test_case['input'])
22+
assert actual_result in test_case['expected']
+8-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import List, TypedDict
1+
from typing import TypedDict
22

33
from . import Solution
44

@@ -8,15 +8,15 @@ class CaseDict(TypedDict):
88
expected: int
99

1010

11-
test_cases: List[CaseDict] = [
12-
{"input": 123, "expected": 321},
13-
{"input": -123, "expected": -321},
14-
{"input": 120, "expected": 21},
15-
{"input": 0, "expected": 0},
11+
test_cases: list[CaseDict] = [
12+
{'input': 123, 'expected': 321},
13+
{'input': -123, 'expected': -321},
14+
{'input': 120, 'expected': 21},
15+
{'input': 0, 'expected': 0},
1616
]
1717

1818

1919
def test_solution():
2020
for test_case in test_cases:
21-
actual_result = Solution().reverse(test_case["input"])
22-
assert actual_result == test_case["expected"]
21+
actual_result = Solution().reverse(test_case['input'])
22+
assert actual_result == test_case['expected']
+8-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import List, TypedDict
1+
from typing import TypedDict
22

33
from . import Solution
44

@@ -8,15 +8,15 @@ class CaseDict(TypedDict):
88
expected: bool
99

1010

11-
test_cases: List[CaseDict] = [
12-
{"input": 121, "expected": True},
13-
{"input": -121, "expected": False},
14-
{"input": 10, "expected": False},
15-
{"input": -101, "expected": False},
11+
test_cases: list[CaseDict] = [
12+
{'input': 121, 'expected': True},
13+
{'input': -121, 'expected': False},
14+
{'input': 10, 'expected': False},
15+
{'input': -101, 'expected': False},
1616
]
1717

1818

1919
def test_solution():
2020
for test_case in test_cases:
21-
actual_result = Solution().isPalindrome(test_case["input"])
22-
assert actual_result == test_case["expected"]
21+
actual_result = Solution().isPalindrome(test_case['input'])
22+
assert actual_result == test_case['expected']

solutions/solution_0011/__init__.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
from typing import List
2-
3-
41
class Solution:
5-
def maxArea(self, height: List[int]) -> int:
2+
def maxArea(self, height: list[int]) -> int:
63
left = 0
74
right = len(height) - 1
85
max_area = 0
+10-10
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
from typing import List, TypedDict
1+
from typing import TypedDict
22

33
import pytest
44

55
from . import Solution
66

77

88
class InputDict(TypedDict):
9-
height: List[int]
9+
height: list[int]
1010

1111

1212
class CaseDict(TypedDict):
@@ -16,16 +16,16 @@ class CaseDict(TypedDict):
1616

1717
test_cases: list[CaseDict] = [
1818
{
19-
"input": {
20-
"height": [1, 8, 6, 2, 5, 4, 8, 3, 7],
19+
'input': {
20+
'height': [1, 8, 6, 2, 5, 4, 8, 3, 7],
2121
},
22-
"expected": 49,
22+
'expected': 49,
2323
},
2424
{
25-
"input": {
26-
"height": [1, 1],
25+
'input': {
26+
'height': [1, 1],
2727
},
28-
"expected": 1,
28+
'expected': 1,
2929
},
3030
]
3131

@@ -35,5 +35,5 @@ class CaseDict(TypedDict):
3535
test_cases,
3636
)
3737
def test_solution(test_case: CaseDict):
38-
result = Solution().maxArea(**test_case["input"])
39-
assert result == test_case["expected"]
38+
result = Solution().maxArea(**test_case['input'])
39+
assert result == test_case['expected']
+9-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import List, TypedDict
1+
from typing import TypedDict
22

33
from . import Solution
44

@@ -8,16 +8,16 @@ class CaseDict(TypedDict):
88
expected: int
99

1010

11-
test_cases: List[CaseDict] = [
12-
{"input": "III", "expected": 3},
13-
{"input": "IV", "expected": 4},
14-
{"input": "IX", "expected": 9},
15-
{"input": "LVIII", "expected": 58},
16-
{"input": "MCMXCIV", "expected": 1994},
11+
test_cases: list[CaseDict] = [
12+
{'input': 'III', 'expected': 3},
13+
{'input': 'IV', 'expected': 4},
14+
{'input': 'IX', 'expected': 9},
15+
{'input': 'LVIII', 'expected': 58},
16+
{'input': 'MCMXCIV', 'expected': 1994},
1717
]
1818

1919

2020
def test_solution():
2121
for test_case in test_cases:
22-
actual_result = Solution().romanToInt(test_case["input"])
23-
assert actual_result == test_case["expected"]
22+
actual_result = Solution().romanToInt(test_case['input'])
23+
assert actual_result == test_case['expected']

solutions/solution_0014/__init__.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
from typing import List
2-
3-
41
class Solution:
5-
def longestCommonPrefix(self, strs: List[str]) -> str:
2+
def longestCommonPrefix(self, strs: list[str]) -> str:
63
result = []
7-
for pair in zip(*strs):
4+
for pair in zip(*strs, strict=False):
85
pair_set = set(pair)
96
if len(pair_set) == 1:
107
result.append(pair_set.pop())
118
else:
129
break
13-
return "".join(result)
10+
return ''.join(result)
+8-8
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
from typing import List, TypedDict
1+
from typing import TypedDict
22

33
from . import Solution
44

55

66
class CaseDict(TypedDict):
7-
input: List[str]
7+
input: list[str]
88
expected: str
99

1010

11-
test_cases: List[CaseDict] = [
12-
{"input": ["flower", "flow", "flight"], "expected": "fl"},
13-
{"input": ["dog", "racecar", "car"], "expected": ""},
14-
{"input": ["cir", "car"], "expected": "c"},
11+
test_cases: list[CaseDict] = [
12+
{'input': ['flower', 'flow', 'flight'], 'expected': 'fl'},
13+
{'input': ['dog', 'racecar', 'car'], 'expected': ''},
14+
{'input': ['cir', 'car'], 'expected': 'c'},
1515
]
1616

1717

1818
def test_solution():
1919
for test_case in test_cases:
20-
actual_result = Solution().longestCommonPrefix(test_case["input"])
21-
assert actual_result == test_case["expected"]
20+
actual_result = Solution().longestCommonPrefix(test_case['input'])
21+
assert actual_result == test_case['expected']

solutions/solution_0015/__init__.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
from typing import List
2-
3-
41
class Solution:
5-
def threeSum(self, nums: List[int]) -> List[List[int]]:
2+
def threeSum(self, nums: list[int]) -> list[list[int]]:
63
results = []
74
nums.sort()
85

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
from typing import List, TypedDict
1+
from typing import TypedDict
22

33
from . import Solution
44

55

66
class CaseDict(TypedDict):
7-
input: List[int]
8-
expected: List[List[int]]
7+
input: list[int]
8+
expected: list[list[int]]
99

1010

11-
test_cases: List[CaseDict] = [
12-
{"input": [-1, 0, 1, 2, -1, -4], "expected": [[-1, -1, 2], [-1, 0, 1]]},
13-
{"input": [], "expected": []},
14-
{"input": [0], "expected": []},
11+
test_cases: list[CaseDict] = [
12+
{'input': [-1, 0, 1, 2, -1, -4], 'expected': [[-1, -1, 2], [-1, 0, 1]]},
13+
{'input': [], 'expected': []},
14+
{'input': [0], 'expected': []},
1515
]
1616

1717

1818
def test_solution():
1919
for test_case in test_cases:
20-
actual_result = Solution().threeSum(test_case["input"])
21-
assert actual_result == test_case["expected"]
20+
actual_result = Solution().threeSum(test_case['input'])
21+
assert actual_result == test_case['expected']
+14-11
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
1-
from typing import List, TypedDict
1+
from typing import TypedDict
22

33
from . import Solution
44

5-
CaseDict = TypedDict('CaseDict', {'input': str, 'expected': bool})
65

6+
class CaseDict(TypedDict):
7+
input: str
8+
expected: bool
79

8-
test_cases: List[CaseDict] = [
9-
{"input": "()", "expected": True},
10-
{"input": "()[]{}", "expected": True},
11-
{"input": "(]", "expected": False},
12-
{"input": "([)]", "expected": False},
13-
{"input": "{[]}", "expected": True},
14-
{"input": "(", "expected": False},
10+
11+
test_cases: list[CaseDict] = [
12+
{'input': '()', 'expected': True},
13+
{'input': '()[]{}', 'expected': True},
14+
{'input': '(]', 'expected': False},
15+
{'input': '([)]', 'expected': False},
16+
{'input': '{[]}', 'expected': True},
17+
{'input': '(', 'expected': False},
1518
]
1619

1720

1821
def test_solution():
1922
for test_case in test_cases:
20-
actual_result = Solution().isValid(test_case["input"])
21-
assert actual_result == test_case["expected"]
23+
actual_result = Solution().isValid(test_case['input'])
24+
assert actual_result == test_case['expected']

0 commit comments

Comments
 (0)