-
Notifications
You must be signed in to change notification settings - Fork 31
Description
Description
The domain.py module contains two standalone functions that are never called anywhere in the codebase. These functions duplicate logic already implemented in the Codec class and serve no purpose:
Location: Lines 42-52 in multiaddr/codecs/domain.py
def to_bytes(proto: Any, string: str) -> bytes:
# Validate using IDNA, but store as UTF-8
idna.encode(string, uts46=True)
return string.encode("utf-8")
def to_string(proto: Any, buf: bytes) -> str:
string = buf.decode("utf-8")
# Validate using IDNA
idna.encode(string, uts46=True)
return stringProblem Analysis
-
Unreferenced Functions: These functions are not imported, called, or referenced anywhere in the project, including:
- The module's
__all__export list - Any test files
- Any other source files
- Any examples
- The module's
-
Duplicate Logic: The functionality is already correctly implemented in the
Codecclass (lines 16-26 and 28-39), which handles:- Empty string validation
- IDNA encoding/validation with
uts46=True - Proper UTF-8 encoding/decoding
- Appropriate error handling
-
Potential for Confusion: Having duplicate implementations can mislead developers about the intended API structure and may lead to maintenance issues if the functions are accidentally used in the future.
Recommended Action
Remove the dead code (lines 42-52) from multiaddr/codecs/domain.py. The standalone functions provide no additional value and their presence only contributes to technical debt.
Verification
To confirm these functions are unused:
- Search for imports of
to_bytesorto_stringfromdomain.py - Check that all domain-related encoding/decoding goes through the
Codecclass - Run static analysis tools (e.g.,
ruff,vulture) to verify no references exist