Skip to content

Commit 9b5b220

Browse files
committed
Remove allow_none_charset from to_unicode
Dead code path: never called with allow_none_charset=True anywhere in the codebase. It also violated its own return type (returned bytes while promising str | None). Removing it simplifies the function and eliminates the last type: ignore in to_unicode.
1 parent 65e2d96 commit 9b5b220

1 file changed

Lines changed: 5 additions & 12 deletions

File tree

emails/utils.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,25 +34,18 @@ def to_native(x: str | bytes | None, charset: str = sys.getdefaultencoding(),
3434

3535

3636
@overload
37-
def to_unicode(x: None, charset: str | None = ..., errors: str = ...,
38-
allow_none_charset: bool = ...) -> None: ...
37+
def to_unicode(x: None, charset: str = ..., errors: str = ...) -> None: ...
3938
@overload
40-
def to_unicode(x: str | bytes, charset: str | None = ..., errors: str = ...,
41-
allow_none_charset: bool = ...) -> str: ...
39+
def to_unicode(x: str | bytes, charset: str = ..., errors: str = ...) -> str: ...
4240
@overload
43-
def to_unicode(x: Any, charset: str | None = ..., errors: str = ...,
44-
allow_none_charset: bool = ...) -> str | None: ...
41+
def to_unicode(x: Any, charset: str = ..., errors: str = ...) -> str | None: ...
4542

46-
def to_unicode(x: Any, charset: str | None = sys.getdefaultencoding(),
47-
errors: str = 'strict',
48-
allow_none_charset: bool = False) -> str | None:
43+
def to_unicode(x: Any, charset: str = sys.getdefaultencoding(),
44+
errors: str = 'strict') -> str | None:
4945
if x is None:
5046
return None
5147
if not isinstance(x, bytes):
5248
return str(x)
53-
if charset is None and allow_none_charset:
54-
return x # type: ignore[return-value] # bytes returned when allow_none_charset=True
55-
assert charset is not None # guaranteed when allow_none_charset is False (default)
5649
return x.decode(charset, errors)
5750

5851

0 commit comments

Comments
 (0)