Skip to content

Commit 966b804

Browse files
committed
[py]: type improvements and make VirtualAuthenticator more pythonic and simplified.
1 parent e90ad6d commit 966b804

File tree

1 file changed

+20
-74
lines changed

1 file changed

+20
-74
lines changed

py/selenium/webdriver/common/virtual_authenticator.py

+20-74
Original file line numberDiff line numberDiff line change
@@ -22,95 +22,41 @@
2222
from enum import Enum
2323

2424

25-
class Protocol(Enum):
26-
"""Protocol to communicate with the authenticator."""
25+
class Protocol(str, Enum):
26+
CTAP2: str = "ctap2"
27+
U2F: str = "ctap1/u2f"
2728

28-
CTAP2 = "ctap2"
29-
U2F = "ctap1/u2f"
3029

31-
32-
class Transport(Enum):
30+
class Transport(str, Enum):
3331
"""Transport method to communicate with the authenticator."""
3432

35-
BLE = "ble"
36-
USB = "usb"
37-
NFC = "nfc"
38-
INTERNAL = "internal"
33+
BLE: str = "ble"
34+
USB: str = "usb"
35+
NFC: str = "nfc"
36+
INTERNAL: str = "internal"
3937

4038

4139
class VirtualAuthenticatorOptions:
4240

41+
# These are so unnecessary but are now public API so we can't remove them without deprecating first.
42+
# These should not be class level state in here.
4343
Protocol = Protocol
4444
Transport = Transport
4545

4646
def __init__(self) -> None:
47-
"""Constructor. Initialize VirtualAuthenticatorOptions object.
48-
49-
:default:
50-
- protocol: Protocol.CTAP2
51-
- transport: Transport.USB
52-
- hasResidentKey: False
53-
- hasUserVerification: False
54-
- isUserConsenting: True
55-
- isUserVerified: False
56-
"""
57-
58-
self._protocol: Protocol = Protocol.CTAP2
59-
self._transport: Transport = Transport.USB
60-
self._has_resident_key: bool = False
61-
self._has_user_verification: bool = False
62-
self._is_user_consenting: bool = True
63-
self._is_user_verified: bool = False
64-
65-
@property
66-
def protocol(self) -> str:
67-
return self._protocol.value
68-
69-
@protocol.setter
70-
def protocol(self, protocol: Protocol) -> None:
71-
self._protocol = protocol
72-
73-
@property
74-
def transport(self) -> str:
75-
return self._transport.value
76-
77-
@transport.setter
78-
def transport(self, transport: Transport) -> None:
79-
self._transport = transport
80-
81-
@property
82-
def has_resident_key(self) -> bool:
83-
return self._has_resident_key
47+
"""Constructor.
8448
85-
@has_resident_key.setter
86-
def has_resident_key(self, value: bool) -> None:
87-
self._has_resident_key = value
88-
89-
@property
90-
def has_user_verification(self) -> bool:
91-
return self._has_user_verification
92-
93-
@has_user_verification.setter
94-
def has_user_verification(self, value: bool) -> None:
95-
self._has_user_verification = value
96-
97-
@property
98-
def is_user_consenting(self) -> bool:
99-
return self._is_user_consenting
100-
101-
@is_user_consenting.setter
102-
def is_user_consenting(self, value: bool) -> None:
103-
self._is_user_consenting = value
104-
105-
@property
106-
def is_user_verified(self) -> bool:
107-
return self._is_user_verified
49+
Initialize VirtualAuthenticatorOptions object.
50+
"""
10851

109-
@is_user_verified.setter
110-
def is_user_verified(self, value: bool) -> None:
111-
self._is_user_verified = value
52+
self.protocol: str = Protocol.CTAP2
53+
self.transport: str = Transport.USB
54+
self.has_resident_key: bool = False
55+
self.has_user_verification: bool = False
56+
self.is_user_consenting: bool = True
57+
self.is_user_verified: bool = False
11258

113-
def to_dict(self) -> typing.Dict[str, typing.Any]:
59+
def to_dict(self) -> typing.Dict[str, typing.Union[str, bool]]:
11460
return {
11561
"protocol": self.protocol,
11662
"transport": self.transport,

0 commit comments

Comments
 (0)