Skip to content

[auth0-python] Add async functions to AsyncAuth0 #13799

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions stubs/auth0-python/@tests/stubtest_allowlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ auth0\.test.*

# Omit _async functions because they aren't present in the code
auth0\..*_async
auth0\.management\.async_auth0\..*

# Inconsistently implemented, ommitted
auth0.asyncify.AsyncRestClient.file_post
Expand Down
61 changes: 61 additions & 0 deletions stubs/auth0-python/auth0/management/async_auth0.pyi
Original file line number Diff line number Diff line change
@@ -1,12 +1,73 @@
from _typeshed import Incomplete
from types import TracebackType
from typing_extensions import Self

from auth0.rest import RestClientOptions as RestClientOptions

from ..asyncify import asyncify as asyncify
from .actions import Actions as Actions
from .attack_protection import AttackProtection as AttackProtection
from .auth0 import Auth0 as Auth0
from .blacklists import Blacklists as Blacklists
from .branding import Branding as Branding
from .client_credentials import ClientCredentials as ClientCredentials
from .client_grants import ClientGrants as ClientGrants
from .clients import Clients as Clients
from .connections import Connections as Connections
from .custom_domains import CustomDomains as CustomDomains
from .device_credentials import DeviceCredentials as DeviceCredentials
from .email_templates import EmailTemplates as EmailTemplates
from .emails import Emails as Emails
from .grants import Grants as Grants
from .guardian import Guardian as Guardian
from .hooks import Hooks as Hooks
from .jobs import Jobs as Jobs
from .log_streams import LogStreams as LogStreams
from .logs import Logs as Logs
from .organizations import Organizations as Organizations
from .prompts import Prompts as Prompts
from .resource_servers import ResourceServers as ResourceServers
from .roles import Roles as Roles
from .rules import Rules as Rules
from .rules_configs import RulesConfigs as RulesConfigs
from .stats import Stats as Stats
from .tenants import Tenants as Tenants
from .tickets import Tickets as Tickets
from .user_blocks import UserBlocks as UserBlocks
from .users import Users as Users
from .users_by_email import UsersByEmail as UsersByEmail
Comment on lines 5 to +38
Copy link
Collaborator

@srittau srittau Apr 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just noticed that these are all re-exported from this file. I don't think we should do that and just use normal import for the items we need in this file (I.e. just from .tenants import Tenants without the as Tenants part.) This applies to all imports, not just the new ones.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I found with this is that my IDE considers these unused if I remove the as import - should I ignore that?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case you can just remove the unused imports.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, by importing these they become attributes of the class - I think this is the correct approach and you should approve as is.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@srittau Bump, thanks.

Copy link
Collaborator

@Avasam Avasam Apr 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure about these?

Python 3.13.1 (main, Dec 19 2024, 14:38:48) [MSC v.1942 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import auth0
>>> auth0.__version__
'4.9.0'
>>> from auth0.management.async_auth0 import AttackProtection
Traceback (most recent call last):
  File "<python-input-2>", line 1, in <module>
    from auth0.management.async_auth0 import AttackProtection
ImportError: cannot import name 'AttackProtection' from 'auth0.management.async_auth0' (E:\Users\Avasam\Documents\Git\typeshed\.venv\Lib\site-packages\auth0\management\async_auth0.py)
>>> from auth0.management.async_auth0 import Auth0
>>> Auth0
<class 'auth0.management.auth0.Auth0'>

by importing these they become attributes of the class

You can't affect what attributes are seen as part of a class simply by importing in a stub. I don't understand what your expectations are here.

Copy link
Collaborator

@Avasam Avasam Apr 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After familiarizing myself further with the source, I think I see what you're trying to do here. If you update this file to the following, you should be good to go:

from types import TracebackType
from typing_extensions import Self

from auth0.rest import RestClientOptions

from .actions import Actions
from .attack_protection import AttackProtection
from .blacklists import Blacklists
from .branding import Branding
from .client_credentials import ClientCredentials
from .client_grants import ClientGrants
from .clients import Clients
from .connections import Connections
from .custom_domains import CustomDomains
from .device_credentials import DeviceCredentials
from .email_templates import EmailTemplates
from .emails import Emails
from .grants import Grants
from .guardian import Guardian
from .hooks import Hooks
from .jobs import Jobs
from .log_streams import LogStreams
from .logs import Logs
from .organizations import Organizations
from .prompts import Prompts
from .resource_servers import ResourceServers
from .roles import Roles
from .rules import Rules
from .rules_configs import RulesConfigs
from .stats import Stats
from .tenants import Tenants
from .tickets import Tickets
from .user_blocks import UserBlocks
from .users import Users
from .users_by_email import UsersByEmail

class AsyncAuth0:
    def __init__(self, domain: str, token: str, rest_options: RestClientOptions | None = None) -> None: ...
    def set_session(self, session) -> None: ...
    async def __aenter__(self) -> Self: ...
    async def __aexit__(
        self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
    ) -> None: ...

	# Same attributes as Auth0
    # See note in stubs/auth0-python/@tests/stubtest_allowlist.txt about _async methods
    actions: Actions
    attack_protection: AttackProtection
    blacklists: Blacklists
    branding: Branding
    client_credentials: ClientCredentials
    client_grants: ClientGrants
    clients: Clients
    connections: Connections
    custom_domains: CustomDomains
    device_credentials: DeviceCredentials
    email_templates: EmailTemplates
    emails: Emails
    grants: Grants
    guardian: Guardian
    hooks: Hooks
    jobs: Jobs
    log_streams: LogStreams
    logs: Logs
    organizations: Organizations
    prompts: Prompts
    resource_servers: ResourceServers
    roles: Roles
    rules_configs: RulesConfigs
    rules: Rules
    stats: Stats
    tenants: Tenants
    tickets: Tickets
    user_blocks: UserBlocks
    users_by_email: UsersByEmail
    users: Users

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep - it doesn't exist except at runtime. So I want to avoid having to add type ignores everywhere in my code that uses this library.

Copy link
Collaborator

@Avasam Avasam Apr 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it doesn't exist except at runtime

In #13799 (comment) I show that these imports don't exist at runtime. If you don't reference the imported names, and the symbols don't exist or aren't meant to be re-exported at runtime, then you don't need to import them in a stub.

As for the dynamically generated AsyncAuth0 attributes, updating this file to #13799 (comment) should get you there.
It'll also resolve the current merge conflict.


class AsyncAuth0:
actions: Incomplete
attack_protection: Incomplete
blacklists: Incomplete
branding: Incomplete
client_credentials: Incomplete
client_grants: Incomplete
clients: Incomplete
connections: Incomplete
custom_domains: Incomplete
device_credentials: Incomplete
email_templates: Incomplete
emails: Incomplete
grants: Incomplete
guardian: Incomplete
hooks: Incomplete
jobs: Incomplete
log_streams: Incomplete
logs: Incomplete
organizations: Incomplete
prompts: Incomplete
resource_servers: Incomplete
roles: Incomplete
rules_configs: Incomplete
rules: Incomplete
stats: Incomplete
tenants: Incomplete
tickets: Incomplete
user_blocks: Incomplete
users_by_email: Incomplete
users: Incomplete
def __init__(self, domain: str, token: str, rest_options: RestClientOptions | None = None) -> None: ...
def set_session(self, session) -> None: ...
async def __aenter__(self) -> Self: ...
Expand Down