Fix Python 3.9 compatibility by replacing union syntax with typing.Optional#376
Merged
olucurious merged 4 commits intomasterfrom Jul 28, 2025
Merged
Fix Python 3.9 compatibility by replacing union syntax with typing.Optional#376olucurious merged 4 commits intomasterfrom
olucurious merged 4 commits intomasterfrom
Conversation
…tional Co-authored-by: olucurious <6186284+olucurious@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Updates in v 2.0.9 break when running on python 3.9
Fix Python 3.9 compatibility by replacing union syntax with typing.Optional
Jul 28, 2025
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR fixes Python 3.9 compatibility by replacing the union type syntax (|) introduced in Python 3.10 with the backward-compatible typing.Optional syntax in function parameter annotations.
- Adds
from typing import Optionalimport to maintain Python 3.5+ compatibility - Replaces all
Type | Noneunion syntax withOptional[Type]in BaseAPI constructor parameters - Ensures PyFCM can be imported without errors on Python 3.9 and earlier versions
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Niccari
pushed a commit
to Niccari/PyFCM
that referenced
this pull request
Jul 30, 2025
Fix Python 3.9 compatibility by replacing union syntax with typing.Optional
Niccari
added a commit
to Niccari/PyFCM
that referenced
this pull request
Jul 30, 2025
note: BaseAPI has been fixed in olucurious#376
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The recent updates in v2.0.9 introduced Python 3.10+ union type syntax (
str | None) in function parameter annotations, which causes aTypeErrorwhen importing PyFCM on Python 3.9:This occurs because the union operator
|for type hints was only introduced in Python 3.10. The error happens inbaseapi.pywhen Python tries to evaluate the type annotations in theBaseAPI.__init__()method.Changes:
from typing import Optionalimport topyfcm/baseapi.pyType | NonewithOptional[Type]in theBaseAPIconstructor:service_account_file: str | None→Optional[str]project_id: str | None→Optional[str]credentials: Credentials | None→Optional[Credentials]proxy_dict: dict | None→Optional[dict]env: str | None→Optional[str]The fix uses
typing.Optional, which is compatible with Python 3.5+ and maintains the exact same API and functionality. All existing tests continue to pass.Fixes #375.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.