Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 4 additions & 4 deletions .secrets.baseline

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ doc8:
ruff:
uv run ruff check .

mypy:
uv run mypy src/tld/
ty:
uv run ty check src/tld/

# ----------------------------------------------------------------------------
# Installation
Expand Down Expand Up @@ -110,6 +110,9 @@ profile-test:
uv run python -m cProfile -o runtests.cprof runtests.py
uv run pyprof2calltree -k -i runtests.cprof

update-tld-names:
uv run update-tld-names

# ----------------------------------------------------------------------------
# Development
# ----------------------------------------------------------------------------
Expand Down Expand Up @@ -141,7 +144,7 @@ clean:
rm -rf testdocs/
rm -rf .coverage
rm -rf .pytest_cache/
rm -rf .mypy_cache/
rm -rf .ty_cache/
rm -rf .ruff_cache/
rm -rf dist/
rm -rf dist_py27/
Expand Down
11 changes: 2 additions & 9 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,6 @@ jinja2==3.1.6
# via sphinx
keyring==25.7.0
# via twine
librt==0.8.1
# via mypy
markdown-it-py==4.0.0
# via rich
markupsafe==3.0.3
Expand All @@ -100,10 +98,6 @@ more-itertools==10.8.0
# via
# jaraco-classes
# jaraco-functools
mypy==1.19.1
# via tld (pyproject.toml)
mypy-extensions==1.1.0
# via mypy
nh3==0.3.3
# via readme-renderer
packaging==26.0
Expand All @@ -117,8 +111,6 @@ packaging==26.0
# wheel
parso==0.8.6
# via jedi
pathspec==1.0.4
# via mypy
pexpect==4.9.0
# via ipython
pkginfo==1.12.1.2
Expand Down Expand Up @@ -240,10 +232,11 @@ traitlets==5.14.3
# matplotlib-inline
twine==6.2.0
# via tld (pyproject.toml)
ty==0.0.34
# via tld (pyproject.toml)
typing-extensions==4.15.0
# via
# anyio
# mypy
# starlette
urllib3==2.6.3
# via
Expand Down
14 changes: 1 addition & 13 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ build = [
]
lint = [
"doc8",
"mypy",
"pydoclint",
"ruff",
"ty",
]
dev = [
"detect-secrets",
Expand Down Expand Up @@ -139,7 +139,6 @@ lint.exclude = [
".eggs",
".git",
".hg",
".mypy_cache",
".nox",
".pants.d",
".ruff_cache",
Expand Down Expand Up @@ -224,16 +223,6 @@ markers = [
"documentation: mark test as a documentation test",
]

# ----------------------------------------------------------------------------
# mypy configuration
# ----------------------------------------------------------------------------
[tool.mypy]
check_untyped_defs = true
warn_unused_ignores = true
warn_redundant_casts = true
warn_unused_configs = true
ignore_missing_imports = true

# ----------------------------------------------------------------------------
# coverage configuration
# ----------------------------------------------------------------------------
Expand Down Expand Up @@ -270,7 +259,6 @@ ignore = [
".hg",
".hypothesis",
".idea",
".mypy_cache",
".nox",
".pre-commit-config.yaml",
".pre-commit-hooks.yaml",
Expand Down
11 changes: 2 additions & 9 deletions requirements/bench.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,6 @@ keyring==25.7.0
# via twine
kiwisolver==1.4.9
# via matplotlib
librt==0.8.1
# via mypy
line-profiler==5.0.2
# via -r requirements/bench.in
markdown-it-py==4.0.0
Expand All @@ -116,10 +114,6 @@ more-itertools==10.8.0
# via
# jaraco-classes
# jaraco-functools
mypy==1.19.1
# via tld (pyproject.toml)
mypy-extensions==1.1.0
# via mypy
nh3==0.3.3
# via readme-renderer
numpy==2.4.2
Expand All @@ -138,8 +132,6 @@ packaging==26.0
# wheel
parso==0.8.6
# via jedi
pathspec==1.0.4
# via mypy
pexpect==4.9.0
# via ipython
pillow==12.1.1
Expand Down Expand Up @@ -282,11 +274,12 @@ traitlets==5.14.3
# matplotlib-inline
twine==6.2.0
# via tld (pyproject.toml)
ty==0.0.34
# via tld (pyproject.toml)
typing-extensions==4.15.0
# via
# anyio
# line-profiler
# mypy
# starlette
urllib3==2.6.3
# via
Expand Down
11 changes: 2 additions & 9 deletions requirements/build.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,6 @@ jinja2==3.1.6
# via sphinx
keyring==25.7.0
# via twine
librt==0.8.1
# via mypy
markdown-it-py==4.0.0
# via rich
markupsafe==3.0.3
Expand All @@ -100,10 +98,6 @@ more-itertools==10.8.0
# via
# jaraco-classes
# jaraco-functools
mypy==1.19.1
# via tld (pyproject.toml)
mypy-extensions==1.1.0
# via mypy
nh3==0.3.3
# via readme-renderer
packaging==26.0
Expand All @@ -117,8 +111,6 @@ packaging==26.0
# wheel
parso==0.8.6
# via jedi
pathspec==1.0.4
# via mypy
pexpect==4.9.0
# via ipython
pkginfo==1.12.1.2
Expand Down Expand Up @@ -242,10 +234,11 @@ traitlets==5.14.3
# matplotlib-inline
twine==6.2.0
# via tld (pyproject.toml)
ty==0.0.34
# via tld (pyproject.toml)
typing-extensions==4.15.0
# via
# anyio
# mypy
# starlette
urllib3==2.6.3
# via
Expand Down
4 changes: 4 additions & 0 deletions runtests.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#!/usr/bin/env python
"""
Used in `make profile-test`. Do NOT use this directly.
"""

import os
import sys

Expand Down
19 changes: 8 additions & 11 deletions src/tld/base.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import logging
from codecs import open as codecs_open
from typing import Dict, ItemsView, Optional, Union, ValuesView
from typing import Dict, ItemsView, Optional, Type, ValuesView
from urllib.request import urlopen

from .exceptions import TldImproperlyConfigured, TldIOError
Expand All @@ -18,14 +17,14 @@


class Registry(type):
REGISTRY: Dict[str, "BaseTLDSourceParser"] = {}
REGISTRY: Dict[str, Type["BaseTLDSourceParser"]] = {}

def __new__(mcs, name, bases, attrs): # noqa: N804
new_cls = type.__new__(mcs, name, bases, attrs)
# Here the name of the class is used as key but it could be any class
# parameter.
if getattr(new_cls, "_uid", None):
mcs.REGISTRY[new_cls._uid] = new_cls
mcs.REGISTRY[new_cls._uid] = new_cls # type: ignore
return new_cls

@property
Expand All @@ -38,16 +37,16 @@ def reset(cls) -> None:

@classmethod
def get(
cls, key: str, default: "BaseTLDSourceParser" = None
) -> Union["BaseTLDSourceParser", None]:
cls, key: str, default: Optional[Type["BaseTLDSourceParser"]] = None
) -> Optional[Type["BaseTLDSourceParser"]]:
return cls.REGISTRY.get(key, default)

@classmethod
def items(cls) -> ItemsView[str, "BaseTLDSourceParser"]:
def items(cls) -> ItemsView[str, Type["BaseTLDSourceParser"]]:
return cls.REGISTRY.items()

@classmethod
def values(cls) -> ValuesView["BaseTLDSourceParser"]:
def values(cls) -> ValuesView[Type["BaseTLDSourceParser"]]:
return cls.REGISTRY.values()

# @classmethod
Expand Down Expand Up @@ -98,9 +97,7 @@ def update_tld_names(cls, fail_silently: bool = False) -> bool:
try:
remote_file = urlopen(cls.source_url)
local_file_abs_path = project_dir(cls.local_path)
with codecs_open(
local_file_abs_path, "wb", encoding="utf8"
) as local_file:
with open(local_file_abs_path, "w", encoding="utf8") as local_file:
local_file.write(remote_file.read().decode("utf8"))
remote_file.close()
LOGGER.info(
Expand Down
Loading
Loading