Skip to content

Cryptography ECB is reported to be abstract #2162

@sk-

Description

@sk-

Describe the Bug

Pyrefly reports that cryptography.hazmat.primitives.ciphers.modes.ECB is abstract, because of how the method is defined.

from cryptography.hazmat.primitives.ciphers import modes

print(modes.ECB())
import abc


class Mode(metaclass=abc.ABCMeta):
    @property
    @abc.abstractmethod
    def name(self) -> str:
        """
        A string naming this mode (e.g. "ECB", "CBC").
        """

    @abc.abstractmethod
    def validate_for_algorithm(self, algorithm: str) -> None:
        """
        Checks that all the necessary invariants of this (mode, algorithm)
        combination are met.
        """


def _check_aes_key_length(self: Mode, algorithm: str) -> None:
    pass


class ECB(Mode):
    name = "ECB"

    validate_for_algorithm = _check_aes_key_length


print(ECB())

In both cases, the code executes correctly, but pyrefly reports

ERROR Cannot instantiate `ECB` because the following members are abstract: `validate_for_algorithm` [bad-instantiation]
 --> pyrefly_cryptography.py:3:16
  |
3 | print(modes.ECB())
  |                ^^
  |
 INFO 1 error

Sandbox Link

https://pyrefly.org/sandbox/?project=N4IgZglgNgpgziAXKOBDAdgEwEYHsAeAdAA4CeSIEAtsbgE4AuABKtgMZMA663bUqcOEwCyuTDAAUVGA1R8BcALys2hAIIAhAMLCZqAJSJuTE0wACxOrmIxGpY6bMrCrOAzpyG0hgAsxDk3EwJnRUaQk4GCgwfSYAWgA%2BJjc6I3RTDK4QTmzs9MyTNWT3CHQAcxCw0orfCCEqMRgmCRhCMsIsgFEtDRyAGiyerRz9QgDMnMm88ad2F2wUz28-THGgpgA3VCgITFQGGAB9MHpD7bL6CF8qCKiwAfPL68RiuljEpgA5XHQYNIKTFNJvkClofDA2ABrIS%2BfYsKBQJi%2BJq-NjwNB0UhMUpbOgQDAMIS4YK1IRSRoPKAXPHXfTjDJsXBUbClfYQH4sOhNbxjEETXLA7jrQ5scFQs7wQ6QmCkQ6wcq%2BW7RF6icSU6lXHxUF4pd5Jb6-f6mYgKbhm9DyQRMboaCSqmCGcahaRMRRdHqCvlbHZ7A7HU6PGla11MEViyESuBSmVymAKnzmyylBgSG0SfT6EB9EAAVwY0DgJHIiBAAGImABVfM7BhYsA5i35n5wc3rE50Kj7Q7oHPM2wSfAvZN615Gkxchg5ujpMA5T697C2F7AfAAX2BWZAZC5YCgpEIDCZUAo5YACqQd3vkhgcAQmIz0JAylO2T9eeWAMowJo%2BBgMYhwIgAD0QHbjAu77vQZRAXGQGYLgbBwEBD5Pi%2BTboEBTDtiwWzQKwsD3j8qEeOhTDWOhhbcGQvg-HEGy2HA7LpG6OQAMyEAAjAATBuq7Zp4ED0QAYtAMAUGgWB4EQZAgKuQA

(Only applicable for extension issues) IDE Information

No response

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions