jawah / charset_normalizer

Truly universal encoding detector in pure Python
https://charset-normalizer.readthedocs.io/en/latest/
MIT License
562 stars 51 forks source link

use TypedDict for return type of legacy detect() #469

Closed pinterior closed 3 months ago

pinterior commented 3 months ago

Problem to solve

when I write something like:

x = charset_normalizer.detect(...)["encoding"]

x is inferred as str | float | None instead of actual str | None.

Change

use custom TypedDict type as the return type of detect method if Python version >= 3.8. (TypedDict is not available in Python 3.7)

pinterior commented 3 months ago

There's a stunt we can put in place to avoid the Python 3.7 blocker. Look at my draft suggestion for more.

that makes sense. committed.

pinterior commented 3 months ago

CI action "MypyC Tests (3.7, macos-latest) (pull_request)" failing due to https://github.com/actions/runner-images/issues/9770 should I create separate PR to use 'macos-13' image for Python 3.7 instead of 'macos-latest'?

Ousret commented 3 months ago

should I create separate PR to use 'macos-13' image for Python 3.7 instead of 'macos-latest'?

no need, I will reorganize the whole thing anyway.