Skip to content

PBKDF2 type hint matches code - #934

Open
yorickdowne wants to merge 1 commit into
Legrandin:masterfrom
yorickdowne:fix/pbkdf2-types
Open

yorickdowne wants to merge 1 commit into
Legrandin:masterfrom
yorickdowne:fix/pbkdf2-types

Conversation

@yorickdowne

@yorickdowne yorickdowne commented Sep 1, 2026 •

Copy link
Copy Markdown

This PR narrowly scratches an itch in my code base, where I need a type ignore for PBKDF2. We can discuss widening it to PBKDF1 and scrypt

PBKDF2 is currently type-hinted with password: str, salt: bytes, but the code does

     password = tobytes(password)
     salt = tobytes(salt)

and the doc string agrees

 password (string or byte string):
 salt (string or byte string):

Potential extension

PBKDF1 also does password = tobytes(password) , so password at last could by bytes or str. The salt is just appended, it must be bytes. This would however also require changing the doc from currently password (string): to password (string or byte string):

scrypt delegates to PBKDF2 with stage_1 = PBKDF2(password, salt, p * 128 * r, 1, prf=prf_hmac_sha256) so bytes absolutely work, but docs and type hints say str. Could be changed in line with PBKDF2

Note tobytes agrees that it could be bytes or str: def tobytes(s: Union[bytes, str]) -> bytes:

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant