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 string
Problem 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
-
Duplicate Logic: The functionality is already correctly implemented in the Codec class (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_bytes or to_string from domain.py
- Check that all domain-related encoding/decoding goes through the
Codec class
- Run static analysis tools (e.g.,
ruff, vulture) to verify no references exist
Description
The
domain.pymodule contains two standalone functions that are never called anywhere in the codebase. These functions duplicate logic already implemented in theCodecclass and serve no purpose:Location: Lines 42-52 in
multiaddr/codecs/domain.pyProblem Analysis
Unreferenced Functions: These functions are not imported, called, or referenced anywhere in the project, including:
__all__export listDuplicate Logic: The functionality is already correctly implemented in the
Codecclass (lines 16-26 and 28-39), which handles:uts46=TruePotential 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:
to_bytesorto_stringfromdomain.pyCodecclassruff,vulture) to verify no references exist