Install idna in mypy nox session
MODIFY
noxfile.py
noxfile.py
@@ -137,6 +137,7 @@ def lint(session):
def mypy(session):
"""Run mypy."""
session.install("mypy==0.812")
+ session.install("idna>=2.0.0")
session.run("mypy", "--version")
session.log("mypy --strict src/urllib3")

MODIFY
src/urllib3/util/url.py
src/urllib3/util/url.py
@@ -300,16 +300,14 @@ def _normalize_host(
def _idna_encode(name: str) -> bytes:
if name and any([ord(x) > 128 for x in name]):
try:
- import idna # type: ignore
+ import idna
except ImportError:
raise LocationParseError(
"Unable to parse URL without the 'idna' module"
) from None
try:
- return typing.cast(
- bytes, idna.encode(name.lower(), strict=True, std3_rules=True)
- )
+ return idna.encode(name.lower(), strict=True, std3_rules=True)
except idna.IDNAError:
raise LocationParseError(
f"Name '{name}' is not a valid IDNA label"

Install idna in mypy nox session