Skip to content

Lazy-import oauthlib/httpx and relax token type hint#6260

Open
FeodorFitsner wants to merge 1 commit intomainfrom
fix-httpx-oauthlib-imports
Open

Lazy-import oauthlib/httpx and relax token type hint#6260
FeodorFitsner wants to merge 1 commit intomainfrom
fix-httpx-oauthlib-imports

Conversation

@FeodorFitsner
Copy link
Contributor

@FeodorFitsner FeodorFitsner commented Mar 5, 2026

Move imports of oauthlib.WebApplicationClient and httpx from module top-level into the functions that use them to enable lazy importing and avoid import-time dependency issues. Also remove the explicit OAuth2Token type annotation from __convert_token to avoid importing oauthlib types at module import. These changes reduce startup import overhead and make the module safer when oauthlib/httpx may not be available until runtime.

Fix #6258

Summary by Sourcery

Make OAuth-related imports lazy and relax token typing to avoid import-time dependencies and reduce startup overhead.

Enhancements:

  • Move oauthlib WebApplicationClient and httpx imports inside the authorization and token-handling methods to enable lazy loading.
  • Remove the explicit OAuth2Token type annotation from the internal token conversion helper to prevent importing oauthlib types at module import time.

Move imports of oauthlib.WebApplicationClient and httpx from module top-level into the functions that use them to enable lazy importing and avoid import-time dependency issues. Also remove the explicit OAuth2Token type annotation from __convert_token to avoid importing oauthlib types at module import. These changes reduce startup import overhead and make the module safer when oauthlib/httpx may not be available until runtime.

Fix #6258
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

We've reviewed this pull request using the Sourcery rules engine

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces lazy imports for oauthlib and httpx within the authorization service to avoid import-time dependency issues and reduce startup overhead.

Changes:

  • Moved httpx and oauthlib.oauth2.WebApplicationClient imports from module scope into the methods that use them
  • Removed the OAuth2Token type annotation from __convert_token to avoid importing oauthlib token types at module import time

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

)

def __convert_token(self, t: OAuth2Token):
def __convert_token(self, t):
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

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

Removing the parameter type entirely loses useful static guarantees for callers and maintainers. To keep lazy-import behavior without depending on oauthlib at import time, consider using a stdlib type such as Mapping[str, object] / dict[str, object] (or Mapping[str, Any]) for t, or a local TYPE_CHECKING import to preserve the precise oauthlib type only for type checkers.

Copilot uses AI. Check for mistakes.
Copy link
Contributor

@ndonkoHenri ndonkoHenri left a comment

Choose a reason for hiding this comment

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

lgtm

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: Flet app built with flet build web crashes after failing to find httpx and oauthlib packages

3 participants