Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect type annotations and mypy ≥0.960 failure in macro_collector.py #50

Open
gilles-peskine-arm opened this issue Sep 23, 2024 · 0 comments
Labels
bug Something isn't working size-s Estimated task size: small (~2d)

Comments

@gilles-peskine-arm
Copy link
Contributor

scripts/mbedtls_framework/macro_collector.py fails to typecheck with mypy ≥0.960.

framework/scripts/mbedtls_framework/macro_collector.py:488: error: No overload variant of "sub" matches argument types "Pattern[Any]", "bytes", "str"
framework/scripts/mbedtls_framework/macro_collector.py:488: note: Possible overload variants:
framework/scripts/mbedtls_framework/macro_collector.py:488: note:     def sub(pattern: Union[str, Pattern[str]], repl: Union[str, Callable[[Match[str]], str]], string: str, count: int = ..., flags: Union[int, RegexFlag] = ...) -> str
framework/scripts/mbedtls_framework/macro_collector.py:488: note:     def sub(pattern: Union[bytes, Pattern[bytes]], repl: Union[Union[bytes, Union[bytearray, memoryview, array[Any], mmap, _CData]], Callable[[Match[bytes]], Union[bytes, Union[bytearray, memoryview, array[Any], mmap, _CData]]]], string: Union[bytes, Union[bytearray, memoryview, array[Any], mmap, _CData]], count: int = ..., flags: Union[int, RegexFlag] = ...) -> bytes

The problem is that mypy's knowledge of read_file_lines is not precise enough, or perhaps outright wrong. The type annotation on read_file_lines.__iter__ says that it's an Iterator[str], but it's actually an iterator over bytes when the context manager was initialized with binary=True. Earlier versions of mypy were fine with that, but since mypy 0.960, they're complaining, I think rightfully, I think thanks to improvements in how overloads for open are handled.

The code isn't wrong, but it has a dependent type, which is too hard for mypy.

The goal of this issue is to fix macro_collector.py so that our code typechecks under modern mypy.

@gilles-peskine-arm gilles-peskine-arm added bug Something isn't working size-s Estimated task size: small (~2d) labels Sep 23, 2024
gilles-peskine-arm added a commit to gilles-peskine-arm/mbedtls that referenced this issue Sep 23, 2024
mypy >=0.960 rejects macro_collectory.py.
Mbed-TLS/mbedtls-framework#50

We currently need mypy >=0.940, <0.960. Pick 0.942, which works, and is the
system version on Ubuntu 22.04.

Signed-off-by: Gilles Peskine <[email protected]>
gilles-peskine-arm added a commit to gilles-peskine-arm/mbedtls that referenced this issue Oct 3, 2024
mypy >=0.960 rejects macro_collector.py.
Mbed-TLS/mbedtls-framework#50

We currently need mypy >=0.940, <0.960. Pick 0.942, which works, and is the
system version on Ubuntu 22.04.

Signed-off-by: Gilles Peskine <[email protected]>
gilles-peskine-arm added a commit to gilles-peskine-arm/mbedtls that referenced this issue Oct 3, 2024
mypy >=0.960 rejects macro_collector.py.
Mbed-TLS/mbedtls-framework#50

We currently need mypy >=0.940, <0.960. Pick 0.942, which works, and is the
system version on Ubuntu 22.04.

Signed-off-by: Gilles Peskine <[email protected]>
gilles-peskine-arm added a commit to gilles-peskine-arm/mbedtls that referenced this issue Oct 3, 2024
mypy >=0.960 rejects macro_collector.py.
Mbed-TLS/mbedtls-framework#50

We currently need mypy >=0.940, <0.960. Pick 0.942, which works, and is the
system version on Ubuntu 22.04.

Signed-off-by: Gilles Peskine <[email protected]>
gilles-peskine-arm added a commit to gilles-peskine-arm/mbedtls that referenced this issue Oct 3, 2024
mypy >=0.960 rejects macro_collector.py.
Mbed-TLS/mbedtls-framework#50

We currently need mypy >=0.940, <0.960. Pick 0.942, which works, and is the
system version on Ubuntu 22.04.

Signed-off-by: Gilles Peskine <[email protected]>
gilles-peskine-arm added a commit that referenced this issue Oct 9, 2024
mypy >=0.960 rejects macro_collector.py.
#50

We currently need mypy >=0.940, <0.960. Pick 0.942, which works, and is the
system version on Ubuntu 22.04.

Signed-off-by: Gilles Peskine <[email protected]>
gilles-peskine-arm added a commit to gilles-peskine-arm/mbedtls that referenced this issue Oct 9, 2024
mypy >=0.960 rejects macro_collector.py.
Mbed-TLS/mbedtls-framework#50

We currently need mypy >=0.940, <0.960. Pick 0.942, which works, and is the
system version on Ubuntu 22.04.

Signed-off-by: Gilles Peskine <[email protected]>
gilles-peskine-arm added a commit to gilles-peskine-arm/mbedtls that referenced this issue Oct 9, 2024
mypy >=0.960 rejects macro_collector.py.
Mbed-TLS/mbedtls-framework#50

We currently need mypy >=0.940, <0.960. Pick 0.942, which works, and is the
system version on Ubuntu 22.04.

Signed-off-by: Gilles Peskine <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working size-s Estimated task size: small (~2d)
Projects
Status: No status
Development

No branches or pull requests

1 participant