Skip to content

Commit 3093f52

Browse files
authored
Merge branch 'master' into add-n-body-simulation-2
2 parents 09237cb + 806b386 commit 3093f52

File tree

13 files changed

+29
-53
lines changed

13 files changed

+29
-53
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,30 +21,9 @@ jobs:
2121
run: |
2222
python -m pip install --upgrade pip setuptools six wheel
2323
python -m pip install mypy pytest-cov -r requirements.txt
24-
# FIXME: #4052 fix mypy errors in other directories and add them here
24+
# FIXME: #4052 fix mypy errors in the exclude directories and remove them below
2525
- run: mypy --ignore-missing-imports
26-
backtracking
27-
bit_manipulation
28-
blockchain
29-
boolean_algebra
30-
cellular_automata
31-
compression
32-
computer_vision
33-
divide_and_conquer
34-
electronics
35-
file_transfer
36-
fractals
37-
fuzzy_logic
38-
genetic_algorithm
39-
geodesy
40-
knapsack
41-
machine_learning
42-
networking_flow
43-
neural_network
44-
physics
45-
quantum
46-
scheduling
47-
sorts
26+
--exclude '(ciphers|conversions|data_structures|digital_image_processing|dynamic_programming|graphs|linear_algebra|maths|matrix|other|project_euler|scripts|searches|strings*)/$' .
4827
- name: Run tests
4928
run: pytest --doctest-modules --ignore=project_euler/ --ignore=scripts/ --cov-report=term-missing:skip-covered --cov=. .
5029
- if: ${{ success() }}

.github/workflows/pre-commit.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
~/.cache/pip
1515
key: ${{ runner.os }}-pre-commit-${{ hashFiles('.pre-commit-config.yaml') }}
1616
- uses: actions/setup-python@v2
17-
- uses: psf/black@stable
17+
- uses: psf/black@20.8b1
1818
- name: Install pre-commit
1919
run: |
2020
python -m pip install --upgrade pip

arithmetic_analysis/gaussian_elimination.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import numpy as np
88

99

10-
def retroactive_resolution(coefficients: np.matrix, vector: np.array) -> np.array:
10+
def retroactive_resolution(coefficients: np.matrix, vector: np.ndarray) -> np.ndarray:
1111
"""
1212
This function performs a retroactive linear system resolution
1313
for triangular matrix
@@ -38,7 +38,7 @@ def retroactive_resolution(coefficients: np.matrix, vector: np.array) -> np.arra
3838
return x
3939

4040

41-
def gaussian_elimination(coefficients: np.matrix, vector: np.array) -> np.array:
41+
def gaussian_elimination(coefficients: np.matrix, vector: np.ndarray) -> np.ndarray:
4242
"""
4343
This function performs Gaussian elimination method
4444
@@ -57,7 +57,7 @@ def gaussian_elimination(coefficients: np.matrix, vector: np.array) -> np.array:
5757
# coefficients must to be a square matrix so we need to check first
5858
rows, columns = np.shape(coefficients)
5959
if rows != columns:
60-
return []
60+
return np.array((), dtype=float)
6161

6262
# augmented matrix
6363
augmented_mat = np.concatenate((coefficients, vector), axis=1)

arithmetic_analysis/in_static_equilibrium.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"""
44
from typing import List
55

6-
from numpy import array, cos, cross, radians, sin
6+
from numpy import array, cos, cross, ndarray, radians, sin
77

88

99
def polar_force(
@@ -23,7 +23,7 @@ def polar_force(
2323

2424

2525
def in_static_equilibrium(
26-
forces: array, location: array, eps: float = 10 ** -1
26+
forces: ndarray, location: ndarray, eps: float = 10 ** -1
2727
) -> bool:
2828
"""
2929
Check if a system is in equilibrium.
@@ -42,7 +42,7 @@ def in_static_equilibrium(
4242
False
4343
"""
4444
# summation of moments is zero
45-
moments: array = cross(location, forces)
45+
moments: ndarray = cross(location, forces)
4646
sum_moments: float = sum(moments)
4747
return abs(sum_moments) < eps
4848

bit_manipulation/binary_shifts.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,7 @@ def arithmetic_right_shift(number: int, shift_amount: int) -> str:
9191
binary_number_length = len(bin(number)[3:]) # Find 2's complement of number
9292
binary_number = bin(abs(number) - (1 << binary_number_length))[3:]
9393
binary_number = (
94-
("1" + "0" * (binary_number_length - len(binary_number)) + binary_number)
95-
if number < 0
96-
else "0"
94+
"1" + "0" * (binary_number_length - len(binary_number)) + binary_number
9795
)
9896

9997
if shift_amount >= len(binary_number):

hashes/adler32.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
"""
1010

1111

12-
def adler32(plain_text: str) -> str:
12+
def adler32(plain_text: str) -> int:
1313
"""
1414
Function implements adler-32 hash.
15-
Itterates and evaluates new value for each character
15+
Iterates and evaluates a new value for each character
1616
1717
>>> adler32('Algorithms')
1818
363791387

hashes/chaos_machine.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
m = 5
77

88
# Buffer Space (with Parameters Space)
9-
buffer_space, params_space = [], []
9+
buffer_space: list[float] = []
10+
params_space: list[float] = []
1011

1112
# Machine Time
1213
machine_time = 0

hashes/enigma_machine.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ def engine(input_character):
4141

4242

4343
if __name__ == "__main__":
44-
decode = input("Type your message:\n")
45-
decode = list(decode)
44+
decode = list(input("Type your message:\n"))
4645
while True:
4746
try:
4847
token = int(input("Please set token:(must be only digits)\n"))
@@ -51,8 +50,8 @@ def engine(input_character):
5150
print(error)
5251
for i in range(token):
5352
rotator()
54-
for i in decode:
55-
engine(i)
53+
for j in decode:
54+
engine(j)
5655
print("\n" + "".join(code))
5756
print(
5857
f"\nYour Token is {token} please write it down.\nIf you want to decode "

hashes/sdbm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"""
2020

2121

22-
def sdbm(plain_text: str) -> str:
22+
def sdbm(plain_text: str) -> int:
2323
"""
2424
Function implements sdbm hash, easy to use, great for bits scrambling.
2525
iterates over each character in the given string and applies function to each of

maths/bailey_borwein_plouffe.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ def _subsum(
7070
sum = 0.0
7171
for sum_index in range(digit_pos_to_extract + precision):
7272
denominator = 8 * sum_index + denominator_addend
73-
exponential_term = 0.0
7473
if sum_index < digit_pos_to_extract:
7574
# if the exponential term is an integer and we mod it by the denominator
7675
# before dividing, only the integer part of the sum will change;

project_euler/problem_074/sol1.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
871: 2,
5252
45361: 2,
5353
872: 2,
54-
45361: 2,
5554
}
5655

5756

web_programming/currency_converter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
URL_BASE = "https://www.amdoren.com/api/currency.php"
1111
TESTING = os.getenv("CI", False)
12-
API_KEY = os.getenv("AMDOREN_API_KEY")
12+
API_KEY = os.getenv("AMDOREN_API_KEY", "")
1313
if not API_KEY and not TESTING:
1414
raise KeyError("Please put your API key in an environment variable.")
1515

web_programming/emails_from_url.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,19 @@
88

99
import re
1010
from html.parser import HTMLParser
11+
from typing import Optional
1112
from urllib import parse
1213

1314
import requests
1415

1516

1617
class Parser(HTMLParser):
17-
def __init__(self, domain: str):
18-
HTMLParser.__init__(self)
19-
self.data = []
18+
def __init__(self, domain: str) -> None:
19+
super().__init__()
20+
self.urls: list[str] = []
2021
self.domain = domain
2122

22-
def handle_starttag(self, tag: str, attrs: str) -> None:
23+
def handle_starttag(self, tag: str, attrs: list[tuple[str, Optional[str]]]) -> None:
2324
"""
2425
This function parse html to take takes url from tags
2526
"""
@@ -29,10 +30,10 @@ def handle_starttag(self, tag: str, attrs: str) -> None:
2930
for name, value in attrs:
3031
# If href is defined, and not empty nor # print it.
3132
if name == "href" and value != "#" and value != "":
32-
# If not already in data.
33-
if value not in self.data:
33+
# If not already in urls.
34+
if value not in self.urls:
3435
url = parse.urljoin(self.domain, value)
35-
self.data.append(url)
36+
self.urls.append(url)
3637

3738

3839
# Get main domain name (example.com)
@@ -59,7 +60,7 @@ def get_sub_domain_name(url: str) -> str:
5960
return parse.urlparse(url).netloc
6061

6162

62-
def emails_from_url(url: str = "https://github.com") -> list:
63+
def emails_from_url(url: str = "https://github.com") -> list[str]:
6364
"""
6465
This function takes url and return all valid urls
6566
"""
@@ -78,7 +79,7 @@ def emails_from_url(url: str = "https://github.com") -> list:
7879

7980
# Get links and loop through
8081
valid_emails = set()
81-
for link in parser.data:
82+
for link in parser.urls:
8283
# open URL.
8384
# read = requests.get(link)
8485
try:

0 commit comments

Comments
 (0)