Skip to content

Commit

Permalink
Merge e84ddc7 into d422286
Browse files Browse the repository at this point in the history
  • Loading branch information
cbowdon authored May 20, 2020
2 parents d422286 + e84ddc7 commit 8c176fc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/tld/base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from codecs import open as codecs_open
from urllib.request import urlopen
from typing import Optional

from .exceptions import (
TldIOError,
Expand All @@ -17,9 +18,9 @@
class BaseTLDSourceParser(metaclass=Registry):
"""Base TLD source parser."""

uid: str = None
source_url: str = None
local_path: str = None
uid: Optional[str] = None
source_url: str
local_path: str

@classmethod
def validate(cls):
Expand Down
11 changes: 10 additions & 1 deletion src/tld/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@ def get_tld_names(
):
return _tld_names

local_file = None
try:
# Load the TLD names file
if isabs(cls.local_path):
Expand Down Expand Up @@ -441,6 +440,9 @@ def get_fld(
if domain_parts is None:
return None

# This should be None when domain_parts is None
# but mypy isn't quite smart enough to figure that out yet
assert non_zero_i is not None
if non_zero_i < 0:
# hostname = tld
return parsed_url.hostname
Expand Down Expand Up @@ -497,6 +499,10 @@ def get_tld(
if domain_parts is None:
return None

# This should be None when domain_parts is None
# but mypy isn't quite smart enough to figure that out yet
assert non_zero_i is not None

if not as_object:
if non_zero_i < 0:
# hostname = tld
Expand All @@ -507,6 +513,9 @@ def get_tld(
# hostname = tld
subdomain = ""
domain = ""
# This is checked in process_url but the type is ambiguous (Optional[str])
# so this assertion is just to satisfy mypy
assert parsed_url.hostname is not None, "No hostname in URL"
_tld = parsed_url.hostname
else:
subdomain = ".".join(domain_parts[:non_zero_i-1])
Expand Down

0 comments on commit 8c176fc

Please sign in to comment.