Conversation

ViktorSky

This pull request introduces comprehensive type annotations to the firebase_admin codebase using PEP 484 standards. All changes have been validated with Pyright in strict mode to enforce consistency and catch potential type errors early.

Goals

  • Enhance developer experience with precise autocomplete and type hints.
  • Catch type-related bugs upfront via static analysis.

Tools

  • Pyright in strict mode for robust type-checking.
  • Manual review of ambiguous or potentially problematic sections.

Configuration Additions

  • pyrightconfig.json: config file created to declare strict-mode settings.

  • firebase_admin/_typing.py: A new central module that defines all custom type aliases, TypedDicts, and Protocols. By consolidating these shared types in one place, we simplify extension and reuse across the package and avoid circular-import issues.

@ViktorSkyViktorSky mentioned this pull request Jun 5, 2025
@ViktorSky

@jamesdaniels @lahirumaramba
Could someone please assign a reviewer to this PR? The previous one was completely ignored, and I closed it because it conflicted with the new Firebase version.

@ViktorSky

This feature requires PR #713 to be approved before linters can take advantage of it.

@lahirumarambalahirumaramba self-requested a review June 10, 2025 15:46
@lahirumarambalahirumaramba self-assigned this Jun 10, 2025
- TypeError: 'ABCMeta' object is not subscriptable
- AttributeError: partially initialized module 'firebase_admin._user_mgt' has no attribute 'UserMetadata' (most likely due to a circular import)
- db.Reference signature
- TypeError: 'ABCMeta' object is not subscriptable
- AttributeError: partially initialized module 'firebase_admin._user_mgt' has no attribute 'UserMetadata' (most likely due to a circular import)
- db.Reference signature
@ViktorSky

tests/test_db.py:907 creates a firebase_admin.db.Reference instance without client.

In this class, the methods assume that client will never be None.

Can you help me here?
Should I add a line that creates an instance when it's None? Or should I add validations in each part where it's referenced?

Choose a reason for hiding this comment

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

Thank you for your contribution! We understand that this is an important addition to the the codebase, but as this was not something we had prioritized in the current roadmap the review process will take some time to complete.

I have added a comment to start the process. Do you have any objections to change the import statements to specific items over importing the entire typings module?

ViktorSky and others added 4 commits June 13, 2025 12:29
- `firebase_admin._auth_utils._parse_error_body`: AttributeError: 'str' object has no attribute 'get'
- `firebase_admin._http_client.HttpClient.headers`: TypeError: 'ABCMeta' object is not subscriptable
- `firebase_admin.db.Reference.__init__`: ValueError: Invalid path: "None". Path must be a string.
- `firebase_admin.functions.TaskQueue._validate_task_options`: TypeError: isinstance() arg 2 must be a type, a tuple of types, or a union
- `firebase_admin.ml.Model._convert_to_millis`: TypeError: can't subtract offset-naive and offset-aware datetimes
@lahirumaramba

Note: you probably won't have to worry about 3.8 compatibility issues as we plan to drop 3.8 in the upcoming major release. See: #892

@ViktorSky

I don't know why the 3.9 test fails, could you check it?

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

Successfully merging this pull request may close these issues.