Skip to content

Commit abfffea

Browse files
authored
Merge pull request #49 from 1Password/andi/prevent-ide-errors
Fix IDE errors around exposing items and secrets APIs
2 parents b8c5e74 + fd4e179 commit abfffea

File tree

4 files changed

+24
-35
lines changed

4 files changed

+24
-35
lines changed

example/example.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import asyncio
22
import os
3-
from onepassword.client import Client
4-
from onepassword.types import Item, ItemField, ItemSection
3+
from onepassword import *
54

65

76
async def main():

src/onepassword/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
# AUTO-GENERATED
12
from .client import Client
23
from .defaults import DEFAULT_INTEGRATION_NAME, DEFAULT_INTEGRATION_VERSION
4+
from .types import * # noqa F403
35
from .secrets import Secrets
46
from .items import Items
57

@@ -11,3 +13,6 @@
1113
"DEFAULT_INTEGRATION_NAME",
1214
"DEFAULT_INTEGRATION_VERSION",
1315
]
16+
17+
if hasattr(types, "__all__"):
18+
__all__ += types.__all__

src/onepassword/client.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# AUTO-GENERATED
12
import weakref
23
from .core import _init_client, _release_client
34
from .defaults import new_default_config
@@ -6,19 +7,23 @@
67

78

89
class Client:
9-
@classmethod
10-
async def authenticate(cls, auth, integration_name, integration_version):
11-
self = cls()
10+
secrets: Secrets
11+
items: Items
12+
1213

13-
self.config = new_default_config(
14-
auth=auth,
15-
integration_name=integration_name,
16-
integration_version=integration_version,
17-
)
18-
client_id = int(await _init_client(self.config))
14+
@classmethod
15+
async def authenticate(cls, auth, integration_name, integration_version):
16+
config = new_default_config(
17+
auth=auth,
18+
integration_name=integration_name,
19+
integration_version=integration_version,
20+
)
21+
client_id = int(await _init_client(config))
1922

20-
self.secrets = Secrets(client_id)
21-
self.items = Items(client_id)
22-
self._finalizer = weakref.finalize(self, _release_client, client_id)
23+
authenticated_client = cls()
2324

24-
return self
25+
authenticated_client.secrets = Secrets(client_id)
26+
authenticated_client.items = Items(client_id)
27+
authenticated_client._finalizer = weakref.finalize(cls, _release_client, client_id)
28+
29+
return authenticated_client

src/onepassword/test_client.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -40,26 +40,6 @@ async def test_invalid_resolve():
4040

4141
## test client constructor
4242

43-
44-
# valid
45-
@pytest.mark.asyncio
46-
async def test_good_client_construction():
47-
client = await onepassword.Client.authenticate(
48-
auth=TOKEN,
49-
integration_name=onepassword_defaults.DEFAULT_INTEGRATION_NAME,
50-
integration_version=onepassword_defaults.DEFAULT_INTEGRATION_VERSION,
51-
)
52-
assert client.config["serviceAccountToken"] == TOKEN
53-
assert (
54-
client.config["integrationName"]
55-
== onepassword_defaults.DEFAULT_INTEGRATION_NAME
56-
)
57-
assert (
58-
client.config["integrationVersion"]
59-
== onepassword_defaults.DEFAULT_INTEGRATION_VERSION
60-
)
61-
62-
6343
# invalid
6444
@pytest.mark.asyncio
6545
async def test_client_construction_no_auth():

0 commit comments

Comments
 (0)