Skip to content

Commit

Permalink
Merge pull request john-kurkowski#255 from john-kurkowski/more-types
Browse files Browse the repository at this point in the history
Check untyped defs
  • Loading branch information
john-kurkowski authored Mar 14, 2022
2 parents 6e2c0e0 + b35a4df commit a7a868e
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ custom_cache_extract = tldextract.TLDExtract(cache_dir='/path/to/your/cache/')
custom_cache_extract('http://www.google.com')

# extract callable that doesn't use caching
no_cache_extract = tldextract.TLDExtract(cache_dir=False)
no_cache_extract = tldextract.TLDExtract(cache_dir=None)
no_cache_extract('http://www.google.com')
```

Expand Down
7 changes: 7 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
[metadata]
license_file = LICENSE

[mypy]
check_untyped_defs = True
disallow_incomplete_defs = True
# TODO: progressively enable more of these aggressive checks
# disallow_untyped_calls = True
# disallow_untyped_defs = True
2 changes: 1 addition & 1 deletion tests/integration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
def test_bad_kwargs():
with pytest.raises(ValueError):
tldextract.TLDExtract(
cache_dir=False, suffix_list_urls=False, fallback_to_snapshot=False
cache_dir=None, suffix_list_urls=(), fallback_to_snapshot=False
)
4 changes: 2 additions & 2 deletions tests/main_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,10 +346,10 @@ def test_cache_timeouts(tmpdir):

def test_tlds_property():
extract_private = tldextract.TLDExtract(
cache_dir=None, suffix_list_urls=None, include_psl_private_domains=True
cache_dir=None, suffix_list_urls=(), include_psl_private_domains=True
)
extract_public = tldextract.TLDExtract(
cache_dir=None, suffix_list_urls=None, include_psl_private_domains=False
cache_dir=None, suffix_list_urls=(), include_psl_private_domains=False
)
assert len(extract_private.tlds) > len(extract_public.tlds)

Expand Down
6 changes: 3 additions & 3 deletions tests/test_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
import os.path
import sys
import types
from typing import Any, cast

import pytest
import tldextract.cache
from tldextract.cache import (DiskCache, get_cache_dir,
get_pkg_unique_identifier)
from tldextract.cache import DiskCache, get_cache_dir, get_pkg_unique_identifier


def test_disk_cache(tmpdir):
Expand All @@ -28,7 +28,7 @@ def test_get_pkg_unique_identifier(monkeypatch):
monkeypatch.setattr(sys, "prefix", "/home/john/.pyenv/versions/myvirtualenv")

mock_version_module = types.ModuleType("tldextract._version", "mocked module")
mock_version_module.version = "1.2.3"
cast(Any, mock_version_module).version = "1.2.3"
monkeypatch.setitem(sys.modules, "tldextract._version", mock_version_module)

assert (
Expand Down
10 changes: 3 additions & 7 deletions tldextract/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def set(self, namespace, key, value):
"unable to cache %s.%s in %s. This could refresh the "
"Public Suffix List over HTTP every app startup. "
"Construct your `TLDExtract` with a writable `cache_dir` or "
"set `cache_dir=False` to silence this warning. %s"
"set `cache_dir=None` to silence this warning. %s"
),
namespace,
key,
Expand Down Expand Up @@ -172,7 +172,7 @@ def run_and_cache(self, func, namespace, kwargs, hashed_argnames):
"unable to cache %s.%s in %s. This could refresh the "
"Public Suffix List over HTTP every app startup. "
"Construct your `TLDExtract` with a writable `cache_dir` or "
"set `cache_dir=False` to silence this warning. %s"
"set `cache_dir=None` to silence this warning. %s"
),
namespace,
key_args,
Expand Down Expand Up @@ -218,11 +218,7 @@ def _fetch_url(session, url, timeout):

def _make_cache_key(inputs):
key = repr(inputs)
try:
key = md5(key).hexdigest()
except TypeError:
key = md5(key.encode("utf8")).hexdigest()
return key
return md5(key.encode("utf8")).hexdigest()


def _make_dir(filename):
Expand Down

0 comments on commit a7a868e

Please sign in to comment.