Skip to content

Type checks started failing on our codebase with v4.4 #514

Closed

Description

@lorinkoz

Checklist

  • I have looked into the Readme and Examples, and have not found a suitable solution or answer.
  • I have looked into the API documentation and have not found a suitable solution or answer.
  • I have searched the issues and have not found a suitable solution or answer.
  • I have searched the Auth0 Community forums and have not found a suitable solution or answer.
  • I agree to the terms within the Auth0 Code of Conduct.

Description

No complaints on v4.3, automatic upgrade PR on v4.4 fails like this:

Screenshot 2023-08-18 at 08 53 26

Example of the code:

import auth0.management as _management

token = get_token_from_somewhere()
auth0 = _management.Auth0(API_DOMAIN, token)

users = auth0.users_by_email.search_users_by_email(...)

Reproduction

[Nothing useful to add here]

Additional context

No response

auth0-python version

4.4

Python version

3.11

Activity

  1. added
    bug
    on Aug 18, 2023
  2. adamjmcgrath commented on Aug 18, 2023

    @adamjmcgrath
    Contributor

    Thanks @lorinkoz - will take a look

  3. dazzag24 commented on Aug 18, 2023

    @dazzag24

    I'm also seeing this issue after just updating to 4.4

  4. lorinkoz commented on Aug 21, 2023

    @lorinkoz
    ContributorAuthor

    Thanks for fixing so quickly! Do you plan to do a patch release for this change alone or do you normally wait for a few more fixes before cutting a release?

  5. adamjmcgrath commented on Aug 21, 2023

    @adamjmcgrath
    Contributor

    Np @lorinkoz - will ship a patch today

  6. adamjmcgrath commented on Aug 21, 2023

    @adamjmcgrath
    Contributor

    @lorinkoz - apologies - it might take a little longer while I fix a releasing issue

    Will update this thread when the patch is up

  7. adamjmcgrath commented on Aug 21, 2023

    @adamjmcgrath
    Contributor

    @lorinkoz 4.4.1 is now available - lmk if you run into any more types issues in the management client

  8. lorinkoz commented on Aug 30, 2023

    @lorinkoz
    ContributorAuthor

    Good day. FYI, the problem remains. I just checked the PR and it seems to be adjusting the mypy config for this repo, but this doesn't have any effect on projects using the package.

  9. adamjmcgrath commented on Aug 30, 2023

    @adamjmcgrath
    Contributor

    Ah, ok - thanks for the heads up @lorinkoz

    @Viicos - do you know a fix for this?

  10. Viicos commented on Aug 30, 2023

    @Viicos
    Contributor

    Well this looks similar to #483 but for the AsyncAuth0 class. Can be fixed by either doing the same thing as:

    def __init__(
    self, domain: str, token: str, rest_options: RestClientOptions | None = None
    ):
    self.actions = Actions(domain, token, rest_options=rest_options)
    self.attack_protection = AttackProtection(
    domain, token, rest_options=rest_options
    )
    self.blacklists = Blacklists(domain, token, rest_options=rest_options)
    self.branding = Branding(domain, token, rest_options=rest_options)
    self.client_credentials = ClientCredentials(
    domain, token, rest_options=rest_options
    )
    self.client_grants = ClientGrants(domain, token, rest_options=rest_options)
    self.clients = Clients(domain, token, rest_options=rest_options)
    self.connections = Connections(domain, token, rest_options=rest_options)
    self.custom_domains = CustomDomains(domain, token, rest_options=rest_options)
    self.device_credentials = DeviceCredentials(
    domain, token, rest_options=rest_options
    )
    self.email_templates = EmailTemplates(domain, token, rest_options=rest_options)
    self.emails = Emails(domain, token, rest_options=rest_options)
    self.grants = Grants(domain, token, rest_options=rest_options)
    self.guardian = Guardian(domain, token, rest_options=rest_options)
    self.hooks = Hooks(domain, token, rest_options=rest_options)
    self.jobs = Jobs(domain, token, rest_options=rest_options)
    self.log_streams = LogStreams(domain, token, rest_options=rest_options)
    self.logs = Logs(domain, token, rest_options=rest_options)
    self.organizations = Organizations(domain, token, rest_options=rest_options)
    self.prompts = Prompts(domain, token, rest_options=rest_options)
    self.resource_servers = ResourceServers(
    domain, token, rest_options=rest_options
    )
    self.roles = Roles(domain, token, rest_options=rest_options)
    self.rules_configs = RulesConfigs(domain, token, rest_options=rest_options)
    self.rules = Rules(domain, token, rest_options=rest_options)
    self.stats = Stats(domain, token, rest_options=rest_options)
    self.tenants = Tenants(domain, token, rest_options=rest_options)
    self.tickets = Tickets(domain, token, rest_options=rest_options)
    self.user_blocks = UserBlocks(domain, token, rest_options=rest_options)
    self.users_by_email = UsersByEmail(domain, token, rest_options=rest_options)
    self.users = Users(domain, token, rest_options=rest_options)

    Or by doing it in a TYPE_CHECKING block

  11. adamjmcgrath commented on Aug 30, 2023

    @adamjmcgrath
    Contributor

    @Viicos We add async variants to every method in the management client at runtime - eg users.get_async(id) would all of these not also need to be defined? can we just opt out of type checking for AsyncAuth0?

  12. Viicos commented on Aug 30, 2023

    @Viicos
    Contributor

    Looking at how it is done currently:

    def __init__(
    self, domain: str, token: str, rest_options: RestClientOptions | None = None
    ) -> None:
    self._services = []
    for name, attr in vars(Auth0(domain, token, rest_options=rest_options)).items():
    cls = asyncify(attr.__class__)
    service = cls(domain=domain, token=token, rest_options=rest_options)
    self._services.append(service)
    setattr(
    self,
    name,
    service,
    )

    And the fact that asyncify returns dynamic stuff as well, it is indeed hard to type check this correctly.

    The fix you did on #515 only affects the current project, as the mypy.ini file is only used when working on auth0-python. Instead, projects depending on auth0-python need to disable this attr-defined error code on their mypy configuration if they want to ignore the error (this means that #515 can be reverted)

  13. adamjmcgrath commented on Aug 30, 2023

    @adamjmcgrath
    Contributor

    Instead, projects depending on auth0-python need to disable this attr-defined error code on their mypy configuration

    I don't think It's reasonable to expect users of this package to have to do this, if there isn't a better solution I'm going to have to remove the py.typed file and revert publishing types until a better solution is available.

  14. added a commit that references this issue on Aug 31, 2023
    8c75c6c
  15. lorinkoz commented on Sep 7, 2023

    @lorinkoz
    ContributorAuthor

    Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions