Skip to content

Commit cc322c1

Browse files
authored
Merge pull request #54 from 1Password/andi/fix-python-type-imports
Export types correctly in wildcards
2 parents abfffea + b88184f commit cc322c1

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

.github/workflows/validate.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,5 @@ jobs:
4747
- name: Lint with Ruff
4848
run: |
4949
pip install ruff
50-
ruff check --output-format=github --exclude=src/onepassword/lib/ .
50+
ruff check --output-format=github --exclude=src/onepassword/lib/,example/ .
5151
continue-on-error: true

example/example.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import os
33
from onepassword import *
44

5-
65
async def main():
76
# Gets your service account token from the OP_SERVICE_ACCOUNT_TOKEN environment variable.
87
token = os.getenv("OP_SERVICE_ACCOUNT_TOKEN")
@@ -24,7 +23,7 @@ async def main():
2423
id="",
2524
title="MyName",
2625
category="Login",
27-
vault_id="vault_id",
26+
vault_id="q73bqltug6xoegr3wkk2zkenoq",
2827
fields=[
2928
ItemField(
3029
id="username",
@@ -48,7 +47,7 @@ async def main():
4847
print(dict(created_item))
4948

5049
# Retrieve an item from your vault.
51-
item = await client.items.get("vault_id", created_item.id)
50+
item = await client.items.get(created_item.vault_id, created_item.id)
5251

5352
print(dict(item))
5453

@@ -59,7 +58,7 @@ async def main():
5958
print(dict(updated_item))
6059

6160
# Delete a item from your vault.
62-
await client.items.delete("vault_id", updated_item.id)
61+
await client.items.delete(created_item.vault_id, updated_item.id)
6362

6463

6564
if __name__ == "__main__":

src/onepassword/__init__.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
from .secrets import Secrets
66
from .items import Items
77

8+
import sys
9+
import inspect
10+
import typing
811

912
__all__ = [
1013
"Client",
@@ -14,5 +17,7 @@
1417
"DEFAULT_INTEGRATION_VERSION",
1518
]
1619

17-
if hasattr(types, "__all__"):
18-
__all__ += types.__all__
20+
for name, obj in inspect.getmembers(sys.modules["onepassword.types"]):
21+
# Add all classes and instances of typing.Literal defined in types.py.
22+
if (inspect.isclass(obj) and inspect.getmodule(obj) == sys.modules["onepassword.types"]) or type(eval(name)) == typing._LiteralGenericAlias:
23+
__all__.append(name)

0 commit comments

Comments
 (0)