Skip to content

Commit 629848e

Browse files
shermanhuigithub-actions
and
github-actions
authored
[mypy] Fix type annotations in data_structures/binary_tree (#5518)
* fix: fix mypy errors Update binary_search_tree `arr` argument to be typed as a list within `find_kth_smallest` function Update return type of `merge_two_binary_trees` as both inputs can be None which means that a None type value can be returned from this function * updating DIRECTORY.md Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
1 parent d82cf52 commit 629848e

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

Diff for: DIRECTORY.md

+1
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@
272272

273273
## Electronics
274274
* [Carrier Concentration](https://github.com/TheAlgorithms/Python/blob/master/electronics/carrier_concentration.py)
275+
* [Coulombs Law](https://github.com/TheAlgorithms/Python/blob/master/electronics/coulombs_law.py)
275276
* [Electric Power](https://github.com/TheAlgorithms/Python/blob/master/electronics/electric_power.py)
276277
* [Ohms Law](https://github.com/TheAlgorithms/Python/blob/master/electronics/ohms_law.py)
277278

Diff for: data_structures/binary_tree/binary_search_tree.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def inorder(self, arr: list, node: Node):
151151

152152
def find_kth_smallest(self, k: int, node: Node) -> int:
153153
"""Return the kth smallest element in a binary search tree"""
154-
arr = []
154+
arr: list = []
155155
self.inorder(arr, node) # append all values to list using inorder traversal
156156
return arr[k - 1]
157157

Diff for: data_structures/binary_tree/merge_two_binary_trees.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
"""
88
from __future__ import annotations
99

10+
from typing import Optional
11+
1012

1113
class Node:
1214
"""
@@ -19,7 +21,7 @@ def __init__(self, value: int = 0) -> None:
1921
self.right: Node | None = None
2022

2123

22-
def merge_two_binary_trees(tree1: Node | None, tree2: Node | None) -> Node:
24+
def merge_two_binary_trees(tree1: Node | None, tree2: Node | None) -> Optional[Node]:
2325
"""
2426
Returns root node of the merged tree.
2527

0 commit comments

Comments
 (0)