Skip to content

[mypy] Fix web_programming directory #4297

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 34 commits into from
Mar 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
2428a10
Experiment: monkeytype stub web_programming
cclauss Mar 28, 2021
1ef01e7
pytest --doctest-modules web_programming
cclauss Mar 28, 2021
aaea821
world_covid19_stats.py
cclauss Mar 28, 2021
6b96969
monkeytype stub web_programming.world_covid19_stats
cclauss Mar 28, 2021
2220b88
Create monkeytype_config.py
cclauss Mar 28, 2021
484855c
updating DIRECTORY.md
Mar 28, 2021
6570772
monkeytype run pytest --doctest-modules
cclauss Mar 28, 2021
73712f1
monkeytype run python3 -m pytest --doctest-modules
cclauss Mar 28, 2021
bb8909f
Update monkeytype.yml
cclauss Mar 28, 2021
5480ec4
/opt/hostedtoolcache/Python/3.9.2/x64/bin/python3/opt/hostedtoolcache…
cclauss Mar 28, 2021
ccf7acf
Update monkeytype.yml
cclauss Mar 28, 2021
2df9939
Update monkeytype.yml
cclauss Mar 28, 2021
5ed45b3
monkeytype run web_programming/*.py
cclauss Mar 28, 2021
7ab64b3
monkeytype list-modules
cclauss Mar 28, 2021
b532d22
Update monkeytype.yml
cclauss Mar 28, 2021
7a14b85
Update monkeytype.yml
cclauss Mar 28, 2021
7090302
Update monkeytype.yml
cclauss Mar 28, 2021
dcd5109
pyannotate
cclauss Mar 28, 2021
560de38
from pyannotate_runtime import collect_types
cclauss Mar 28, 2021
3546524
typing: API_KEY is a str
cclauss Mar 28, 2021
da9ec61
pyannotate emails_from_url.py
cclauss Mar 28, 2021
8cc34cd
pyannotate web_programming/emails_from_url.py
cclauss Mar 28, 2021
d649a70
Update world_covid19_stats.py
cclauss Mar 28, 2021
5178056
Delete monkeytype_config.py
cclauss Mar 28, 2021
a2f7d42
updating DIRECTORY.md
Mar 28, 2021
3e6fcdc
Apply pyannotate suggestions to emails_from_url.py
cclauss Mar 28, 2021
b36d324
mypy web_programming/emails_from_url.py
cclauss Mar 28, 2021
b3a99d8
super().__init__()
cclauss Mar 28, 2021
7c01695
mypy --ignore-missing-imports web_programming/emails_from_url.py
cclauss Mar 28, 2021
92caa16
Update emails_from_url.py
cclauss Mar 28, 2021
aabeb4c
self.urls: list[str] = []
cclauss Mar 28, 2021
e3f3749
mypy: Fix web_programming directory
cclauss Mar 28, 2021
6d7fd3a
Delete monkeytype.yml
cclauss Mar 28, 2021
648c047
Merge branch 'master' into monkeytype-stub-web_programming
dhruvmanila Mar 31, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
python -m pip install mypy pytest-cov -r requirements.txt
# FIXME: #4052 fix mypy errors in the exclude directories and remove them below
- run: mypy --ignore-missing-imports
--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*)/$' .
--exclude '(arithmetic_analysis|ciphers|conversions|data_structures|digital_image_processing|dynamic_programming|graphs|hashes|linear_algebra|maths|matrix|other|project_euler|scripts|searches|strings*)/$' .
- name: Run tests
run: pytest --doctest-modules --ignore=project_euler/ --ignore=scripts/ --cov-report=term-missing:skip-covered --cov=. .
- if: ${{ success() }}
Expand Down
2 changes: 1 addition & 1 deletion web_programming/currency_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

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

Expand Down
19 changes: 10 additions & 9 deletions web_programming/emails_from_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,19 @@

import re
from html.parser import HTMLParser
from typing import Optional
from urllib import parse

import requests


class Parser(HTMLParser):
def __init__(self, domain: str):
HTMLParser.__init__(self)
self.data = []
def __init__(self, domain: str) -> None:
super().__init__()
self.urls: list[str] = []
self.domain = domain

def handle_starttag(self, tag: str, attrs: str) -> None:
def handle_starttag(self, tag: str, attrs: list[tuple[str, Optional[str]]]) -> None:
"""
This function parse html to take takes url from tags
"""
Expand All @@ -29,10 +30,10 @@ def handle_starttag(self, tag: str, attrs: str) -> None:
for name, value in attrs:
# If href is defined, and not empty nor # print it.
if name == "href" and value != "#" and value != "":
# If not already in data.
if value not in self.data:
# If not already in urls.
if value not in self.urls:
url = parse.urljoin(self.domain, value)
self.data.append(url)
self.urls.append(url)


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


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

# Get links and loop through
valid_emails = set()
for link in parser.data:
for link in parser.urls:
# open URL.
# read = requests.get(link)
try:
Expand Down