Skip to content

Commit

Permalink
use TypedDict for return type of legacy detect() (#469)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: TAHRI Ahmed R. <Ousret@users.noreply.github.com>
  • Loading branch information
pinterior and Ousret authored May 18, 2024
1 parent c9c80ef commit 816c998
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions charset_normalizer/legacy.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
from typing import Any, Dict, Optional, Union
from __future__ import annotations

from typing import TYPE_CHECKING, Any, Optional
from warnings import warn

from .api import from_bytes
from .constant import CHARDET_CORRESPONDENCE

# TODO: remove this check when dropping Python 3.7 support
if TYPE_CHECKING:
from typing_extensions import TypedDict

class ResultDict(TypedDict):
encoding: Optional[str]
language: str
confidence: Optional[float]


def detect(
byte_str: bytes, should_rename_legacy: bool = False, **kwargs: Any
) -> Dict[str, Optional[Union[str, float]]]:
) -> ResultDict:
"""
chardet legacy method
Detect the encoding of the given byte string. It should be mostly backward-compatible.
Expand Down

0 comments on commit 816c998

Please sign in to comment.