Skip to content

Commit cd81f1b

Browse files
cclaussgithub-actionsdhruvmanila
authored
[mypy] Fix web_programming directory (TheAlgorithms#4297)
* Update world_covid19_stats.py * Delete monkeytype_config.py * updating DIRECTORY.md * Apply pyannotate suggestions to emails_from_url.py * mypy web_programming/emails_from_url.py * super().__init__() * mypy --ignore-missing-imports web_programming/emails_from_url.py * Update emails_from_url.py * self.urls: list[str] = [] * mypy: Fix web_programming directory Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Co-authored-by: Dhruv Manilawala <[email protected]>
1 parent 0636343 commit cd81f1b

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

Diff for: .github/workflows/build.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
python -m pip install mypy pytest-cov -r requirements.txt
2424
# FIXME: #4052 fix mypy errors in the exclude directories and remove them below
2525
- run: mypy --ignore-missing-imports
26-
--exclude '(arithmetic_analysis|ciphers|conversions|data_structures|digital_image_processing|dynamic_programming|graphs|hashes|linear_algebra|maths|matrix|other|project_euler|scripts|searches|strings|web_programming*)/$' .
26+
--exclude '(arithmetic_analysis|ciphers|conversions|data_structures|digital_image_processing|dynamic_programming|graphs|hashes|linear_algebra|maths|matrix|other|project_euler|scripts|searches|strings*)/$' .
2727
- name: Run tests
2828
run: pytest --doctest-modules --ignore=project_euler/ --ignore=scripts/ --cov-report=term-missing:skip-covered --cov=. .
2929
- if: ${{ success() }}

Diff for: web_programming/currency_converter.py

+1-1
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

Diff for: web_programming/emails_from_url.py

+10-9
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)