File tree 7 files changed +19
-16
lines changed
7 files changed +19
-16
lines changed Original file line number Diff line number Diff line change 23
23
python -m pip install mypy pytest-cov -r requirements.txt
24
24
# FIXME: #4052 fix mypy errors in the exclude directories and remove them below
25
25
- run : mypy --ignore-missing-imports
26
- --exclude '(conversions| data_structures|digital_image_processing|dynamic_programming|graphs|linear_algebra|maths|matrix|other|project_euler|scripts|searches|strings*)/$' .
26
+ --exclude '(data_structures|digital_image_processing|dynamic_programming|graphs|linear_algebra|maths|matrix|other|project_euler|scripts|searches|strings*)/$' .
27
27
- name : Run tests
28
28
run : pytest --doctest-modules --ignore=project_euler/ --ignore=scripts/ --cov-report=term-missing:skip-covered --cov=. .
29
29
- if : ${{ success() }}
Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ def bin_to_octal(bin_string: str) -> str:
28
28
bin_string = "0" + bin_string
29
29
bin_string_in_3_list = [
30
30
bin_string [index : index + 3 ]
31
- for index , value in enumerate ( bin_string )
31
+ for index in range ( len ( bin_string ) )
32
32
if index % 3 == 0
33
33
]
34
34
for bin_group in bin_string_in_3_list :
Original file line number Diff line number Diff line change @@ -28,9 +28,9 @@ def decimal_to_binary(num: int) -> str:
28
28
TypeError: 'str' object cannot be interpreted as an integer
29
29
"""
30
30
31
- if type (num ) == float :
31
+ if isinstance (num , float ) :
32
32
raise TypeError ("'float' object cannot be interpreted as an integer" )
33
- if type (num ) == str :
33
+ if isinstance (num , str ) :
34
34
raise TypeError ("'str' object cannot be interpreted as an integer" )
35
35
36
36
if num == 0 :
@@ -42,7 +42,7 @@ def decimal_to_binary(num: int) -> str:
42
42
negative = True
43
43
num = - num
44
44
45
- binary = []
45
+ binary : list [ int ] = []
46
46
while num > 0 :
47
47
binary .insert (0 , num % 2 )
48
48
num >>= 1
Original file line number Diff line number Diff line change 21
21
}
22
22
23
23
24
- def decimal_to_hexadecimal (decimal ) :
24
+ def decimal_to_hexadecimal (decimal : float ) -> str :
25
25
"""
26
26
take integer decimal value, return hexadecimal representation as str beginning
27
27
with 0x
@@ -58,6 +58,7 @@ def decimal_to_hexadecimal(decimal):
58
58
True
59
59
"""
60
60
assert type (decimal ) in (int , float ) and decimal == int (decimal )
61
+ decimal = int (decimal )
61
62
hexadecimal = ""
62
63
negative = False
63
64
if decimal < 0 :
Original file line number Diff line number Diff line change @@ -17,14 +17,14 @@ def decimal_to_octal(num: int) -> str:
17
17
counter = 0
18
18
while num > 0 :
19
19
remainder = num % 8
20
- octal = octal + (remainder * math .pow (10 , counter ))
20
+ octal = octal + (remainder * math .floor ( math . pow (10 , counter ) ))
21
21
counter += 1
22
22
num = math .floor (num / 8 ) # basically /= 8 without remainder if any
23
23
# This formatting removes trailing '.0' from `octal`.
24
24
return f"0o{ int (octal )} "
25
25
26
26
27
- def main ():
27
+ def main () -> None :
28
28
"""Print octal equivalents of decimal numbers."""
29
29
print ("\n 2 in octal is:" )
30
30
print (decimal_to_octal (2 )) # = 2
Original file line number Diff line number Diff line change @@ -59,10 +59,12 @@ def convert_si_prefix(
59
59
1000
60
60
"""
61
61
if isinstance (known_prefix , str ):
62
- known_prefix : SI_Unit = SI_Unit [known_prefix .lower ()]
62
+ known_prefix = SI_Unit [known_prefix .lower ()]
63
63
if isinstance (unknown_prefix , str ):
64
- unknown_prefix : SI_Unit = SI_Unit [unknown_prefix .lower ()]
65
- unknown_amount = known_amount * (10 ** (known_prefix .value - unknown_prefix .value ))
64
+ unknown_prefix = SI_Unit [unknown_prefix .lower ()]
65
+ unknown_amount : float = known_amount * (
66
+ 10 ** (known_prefix .value - unknown_prefix .value )
67
+ )
66
68
return unknown_amount
67
69
68
70
@@ -85,10 +87,10 @@ def convert_binary_prefix(
85
87
1024
86
88
"""
87
89
if isinstance (known_prefix , str ):
88
- known_prefix : Binary_Unit = Binary_Unit [known_prefix .lower ()]
90
+ known_prefix = Binary_Unit [known_prefix .lower ()]
89
91
if isinstance (unknown_prefix , str ):
90
- unknown_prefix : Binary_Unit = Binary_Unit [unknown_prefix .lower ()]
91
- unknown_amount = known_amount * (
92
+ unknown_prefix = Binary_Unit [unknown_prefix .lower ()]
93
+ unknown_amount : float = known_amount * (
92
94
2 ** ((known_prefix .value - unknown_prefix .value ) * 10 )
93
95
)
94
96
return unknown_amount
Original file line number Diff line number Diff line change 29
29
-> Wikipedia reference: https://en.wikipedia.org/wiki/Dalton_(unit)
30
30
"""
31
31
32
- KILOGRAM_CHART = {
32
+ KILOGRAM_CHART : dict [ str , float ] = {
33
33
"kilogram" : 1 ,
34
34
"gram" : pow (10 , 3 ),
35
35
"milligram" : pow (10 , 6 ),
42
42
"atomic-mass-unit" : 6.022136652e26 ,
43
43
}
44
44
45
- WEIGHT_TYPE_CHART = {
45
+ WEIGHT_TYPE_CHART : dict [ str , float ] = {
46
46
"kilogram" : 1 ,
47
47
"gram" : pow (10 , - 3 ),
48
48
"milligram" : pow (10 , - 6 ),
You can’t perform that action at this time.
0 commit comments