Skip to content

Commit 8465877

Browse files
authored
[passlib] Small changes (#14204)
* Add a few `Self` return annotations. * Add a few `# type: ignore[override]`. * Add a few `@deprecated` annotations. Should help with #14194
1 parent cac9957 commit 8465877

File tree

16 files changed

+62
-43
lines changed

16 files changed

+62
-43
lines changed

stubs/passlib/passlib/handlers/argon2.pyi

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from typing import Any, ClassVar
2+
from typing_extensions import Self
23

34
import passlib.utils.handlers as uh
45

@@ -51,24 +52,24 @@ class _Argon2Common( # type: ignore[misc]
5152
@classmethod
5253
def identify(cls, hash): ...
5354
@classmethod
54-
def from_string(cls, hash): ...
55+
def from_string(cls, hash) -> Self: ... # type: ignore[override]
5556
def __init__(self, type=None, type_d: bool = False, version=None, memory_cost=None, data=None, **kwds) -> None: ...
5657

5758
class _NoBackend(_Argon2Common):
5859
@classmethod
59-
def hash(cls, secret): ...
60+
def hash(cls, secret): ... # type: ignore[override]
6061
@classmethod
61-
def verify(cls, secret, hash): ...
62+
def verify(cls, secret, hash): ... # type: ignore[override]
6263
@classmethod
63-
def genhash(cls, secret, config): ...
64+
def genhash(cls, secret, config): ... # type: ignore[override]
6465

6566
class _CffiBackend(_Argon2Common):
6667
@classmethod
67-
def hash(cls, secret): ...
68+
def hash(cls, secret): ... # type: ignore[override]
6869
@classmethod
69-
def verify(cls, secret, hash): ...
70+
def verify(cls, secret, hash): ... # type: ignore[override]
7071
@classmethod
71-
def genhash(cls, secret, config): ...
72+
def genhash(cls, secret, config): ... # type: ignore[override]
7273

7374
class _PureBackend(_Argon2Common): ...
7475

stubs/passlib/passlib/handlers/bcrypt.pyi

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from typing import Any, ClassVar
2+
from typing_extensions import Self
23

34
import passlib.utils.handlers as uh
45

@@ -19,9 +20,9 @@ class _BcryptCommon(uh.SubclassBackendMixin, uh.TruncateMixin, uh.HasManyIdents,
1920
rounds_cost: ClassVar[str]
2021
truncate_size: ClassVar[int | None]
2122
@classmethod
22-
def from_string(cls, hash): ...
23+
def from_string(cls, hash) -> Self: ... # type: ignore[override]
2324
@classmethod
24-
def needs_update(cls, hash, **kwds): ...
25+
def needs_update(cls, hash, **kwds): ... # type: ignore[override]
2526
@classmethod
2627
def normhash(cls, hash): ...
2728

@@ -50,7 +51,7 @@ class bcrypt_sha256(_wrapped_bcrypt):
5051
@classmethod
5152
def identify(cls, hash): ...
5253
@classmethod
53-
def from_string(cls, hash): ...
54+
def from_string(cls, hash) -> Self: ... # type: ignore[override]
5455
def __init__(self, version=None, **kwds) -> None: ...
5556

5657
__all__ = ["bcrypt"]

stubs/passlib/passlib/handlers/cisco.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from typing import ClassVar
2+
from typing_extensions import Self
23

34
import passlib.utils.handlers as uh
45

@@ -20,7 +21,7 @@ class cisco_type7(uh.GenericHandler):
2021
@classmethod
2122
def using(cls, salt: int | None = None, **kwds): ... # type: ignore[override]
2223
@classmethod
23-
def from_string(cls, hash): ...
24+
def from_string(cls, hash) -> Self: ... # type: ignore[override]
2425
salt: int
2526
def __init__(self, salt: int | None = None, **kwds) -> None: ...
2627
@classmethod

stubs/passlib/passlib/handlers/des_crypt.pyi

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from typing import ClassVar
2+
from typing_extensions import Self
23

34
import passlib.utils.handlers as uh
45

@@ -11,7 +12,7 @@ class des_crypt(uh.TruncateMixin, uh.HasManyBackends, uh.HasSalt, uh.GenericHand
1112
salt_chars: ClassVar[str]
1213
truncate_size: ClassVar[int]
1314
@classmethod
14-
def from_string(cls, hash): ...
15+
def from_string(cls, hash) -> Self: ... # type: ignore[override]
1516
backends: ClassVar[tuple[str, ...]]
1617

1718
class bsdi_crypt(uh.HasManyBackends, uh.HasRounds, uh.HasSalt, uh.GenericHandler): # type: ignore[misc]
@@ -26,9 +27,9 @@ class bsdi_crypt(uh.HasManyBackends, uh.HasRounds, uh.HasSalt, uh.GenericHandler
2627
max_rounds: ClassVar[int]
2728
rounds_cost: ClassVar[str]
2829
@classmethod
29-
def from_string(cls, hash): ...
30+
def from_string(cls, hash) -> Self: ... # type: ignore[override]
3031
@classmethod
31-
def using(cls, **kwds): ...
32+
def using(cls, **kwds): ... # type: ignore[override]
3233
backends: ClassVar[tuple[str, ...]]
3334

3435
class bigcrypt(uh.HasSalt, uh.GenericHandler):
@@ -38,7 +39,7 @@ class bigcrypt(uh.HasSalt, uh.GenericHandler):
3839
max_salt_size: ClassVar[int]
3940
salt_chars: ClassVar[str]
4041
@classmethod
41-
def from_string(cls, hash): ...
42+
def from_string(cls, hash) -> Self: ... # type: ignore[override]
4243

4344
class crypt16(uh.TruncateMixin, uh.HasSalt, uh.GenericHandler): # type: ignore[misc]
4445
name: ClassVar[str]
@@ -49,6 +50,6 @@ class crypt16(uh.TruncateMixin, uh.HasSalt, uh.GenericHandler): # type: ignore[
4950
salt_chars: ClassVar[str]
5051
truncate_size: ClassVar[int]
5152
@classmethod
52-
def from_string(cls, hash): ...
53+
def from_string(cls, hash) -> Self: ... # type: ignore[override]
5354

5455
__all__ = ["des_crypt", "bsdi_crypt", "bigcrypt", "crypt16"]

stubs/passlib/passlib/handlers/digests.pyi

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
from typing import Any, ClassVar
1+
from _typeshed import Incomplete
2+
from typing import ClassVar
3+
from typing_extensions import deprecated
24

35
import passlib.utils.handlers as uh
46

@@ -8,11 +10,11 @@ class HexDigestHash(uh.StaticHandler):
810

911
def create_hex_hash(digest, module="passlib.handlers.digests", django_name=None, required: bool = True): ...
1012

11-
hex_md4: Any
12-
hex_md5: Any
13-
hex_sha1: Any
14-
hex_sha256: Any
15-
hex_sha512: Any
13+
hex_md4: Incomplete
14+
hex_md5: Incomplete
15+
hex_sha1: Incomplete
16+
hex_sha256: Incomplete
17+
hex_sha512: Incomplete
1618

1719
class htdigest(uh.MinimalHandler):
1820
name: ClassVar[str]
@@ -25,8 +27,10 @@ class htdigest(uh.MinimalHandler):
2527
def verify(cls, secret, hash, user, realm, encoding: str = "utf-8"): ... # type: ignore[override]
2628
@classmethod
2729
def identify(cls, hash): ...
30+
@deprecated("Deprecated since Passlib 1.7, will be removed in 2.0")
2831
@classmethod
29-
def genconfig(cls): ...
32+
def genconfig(cls): ... # type: ignore[override]
33+
@deprecated("Deprecated since Passlib 1.7, will be removed in 2.0")
3034
@classmethod
3135
def genhash(cls, secret, config, user, realm, encoding=None): ... # type: ignore[override]
3236

stubs/passlib/passlib/handlers/django.pyi

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from typing import Any, ClassVar
2+
from typing_extensions import Self
23

34
import passlib.utils.handlers as uh
45
from passlib.handlers.bcrypt import _wrapped_bcrypt
@@ -9,12 +10,12 @@ class DjangoSaltedHash(uh.HasSalt, uh.GenericHandler):
910
salt_chars: ClassVar[str]
1011
checksum_chars: ClassVar[str]
1112
@classmethod
12-
def from_string(cls, hash): ...
13+
def from_string(cls, hash) -> Self: ... # type: ignore[override]
1314

1415
class DjangoVariableHash(uh.HasRounds, DjangoSaltedHash): # type: ignore[misc]
1516
min_rounds: ClassVar[int]
1617
@classmethod
17-
def from_string(cls, hash): ...
18+
def from_string(cls, hash) -> Self: ... # type: ignore[override]
1819

1920
class django_salted_sha1(DjangoSaltedHash):
2021
name: ClassVar[str]
@@ -37,7 +38,7 @@ class django_bcrypt_sha256(_wrapped_bcrypt):
3738
@classmethod
3839
def identify(cls, hash): ...
3940
@classmethod
40-
def from_string(cls, hash): ...
41+
def from_string(cls, hash) -> Self: ... # type: ignore[override]
4142

4243
class django_pbkdf2_sha256(DjangoVariableHash):
4344
name: ClassVar[str]
@@ -70,7 +71,7 @@ class django_des_crypt(uh.TruncateMixin, uh.HasSalt, uh.GenericHandler): # type
7071
truncate_size: ClassVar[int]
7172
use_duplicate_salt: bool
7273
@classmethod
73-
def from_string(cls, hash): ...
74+
def from_string(cls, hash) -> Self: ... # type: ignore[override]
7475

7576
class django_disabled(DisabledHash, uh.StaticHandler):
7677
name: ClassVar[str]

stubs/passlib/passlib/handlers/fshp.pyi

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from typing import Any, ClassVar
2+
from typing_extensions import Self
23

34
import passlib.utils.handlers as uh
45

@@ -21,8 +22,8 @@ class fshp(uh.HasRounds, uh.HasRawSalt, uh.HasRawChecksum, uh.GenericHandler):
2122
@property
2223
def checksum_alg(self): ...
2324
@property
24-
def checksum_size(self): ...
25+
def checksum_size(self): ... # type: ignore[override]
2526
@classmethod
26-
def from_string(cls, hash): ...
27+
def from_string(cls, hash) -> Self: ... # type: ignore[override]
2728

2829
__all__ = ["fshp"]

stubs/passlib/passlib/handlers/ldap_digests.pyi

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from typing import ClassVar
2+
from typing_extensions import Self
23

34
import passlib.utils.handlers as uh
45
from passlib.handlers.misc import plaintext
@@ -32,7 +33,7 @@ class _SaltedBase64DigestHelper(uh.HasRawSalt, uh.HasRawChecksum, uh.GenericHand
3233
max_salt_size: ClassVar[int]
3334
default_salt_size: ClassVar[int]
3435
@classmethod
35-
def from_string(cls, hash): ...
36+
def from_string(cls, hash) -> Self: ... # type: ignore[override]
3637

3738
class ldap_md5(_Base64DigestHelper):
3839
name: ClassVar[str]
@@ -67,7 +68,7 @@ class ldap_salted_sha512(_SaltedBase64DigestHelper):
6768
class ldap_plaintext(plaintext):
6869
name: ClassVar[str]
6970
@classmethod
70-
def genconfig(cls): ...
71+
def genconfig(cls): ... # type: ignore[override]
7172
@classmethod
7273
def identify(cls, hash): ...
7374

stubs/passlib/passlib/handlers/md5_crypt.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from typing import ClassVar
2+
from typing_extensions import Self
23

34
import passlib.utils.handlers as uh
45

@@ -8,7 +9,7 @@ class _MD5_Common(uh.HasSalt, uh.GenericHandler):
89
max_salt_size: ClassVar[int]
910
salt_chars: ClassVar[str]
1011
@classmethod
11-
def from_string(cls, hash): ...
12+
def from_string(cls, hash) -> Self: ... # type: ignore[override]
1213

1314
class md5_crypt(uh.HasManyBackends, _MD5_Common):
1415
name: ClassVar[str]

stubs/passlib/passlib/handlers/misc.pyi

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from typing import Any, ClassVar
2+
from typing_extensions import deprecated
23

34
import passlib.utils.handlers as uh
45
from passlib.ifc import DisabledHash
@@ -43,8 +44,10 @@ class plaintext(uh.MinimalHandler):
4344
def hash(cls, secret: str | bytes, encoding=None): ... # type: ignore[override]
4445
@classmethod
4546
def verify(cls, secret: str | bytes, hash: str | bytes, encoding: str | None = None): ... # type: ignore[override]
47+
@deprecated("Deprecated since Passlib 1.7, will be removed in 2.0")
4648
@classmethod
47-
def genconfig(cls): ...
49+
def genconfig(cls): ... # type: ignore[override]
50+
@deprecated("Deprecated since Passlib 1.7, will be removed in 2.0")
4851
@classmethod
4952
def genhash(cls, secret, config, encoding: str | None = None): ... # type: ignore[override]
5053

0 commit comments

Comments
 (0)