77
88import base64
99from enum import Enum
10- from typing import TYPE_CHECKING , Annotated , Any , Literal , NewType
10+ from typing import TYPE_CHECKING , Annotated , Any , Literal , NewType , Optional , Union , get_args
1111
1212import sigstore .errors
1313from annotated_types import MinLen # noqa: TCH002
@@ -187,7 +187,7 @@ def verify(
187187 dist : Distribution ,
188188 * ,
189189 staging : bool = False ,
190- ) -> tuple [str , dict [str , Any ] | None ]:
190+ ) -> tuple [str , Optional [ dict [str , Any ]] ]:
191191 """Verify against an existing Python distribution.
192192
193193 The `identity` can be an object confirming to
@@ -203,7 +203,8 @@ def verify(
203203 # NOTE: Can't do `isinstance` with `Publisher` since it's
204204 # a `_GenericAlias`; instead we punch through to the inner
205205 # `_Publisher` union.
206- if isinstance (identity , _Publisher ):
206+ # Use of typing.get_args is needed for Python < 3.10
207+ if isinstance (identity , get_args (_Publisher )):
207208 policy = identity ._as_policy () # noqa: SLF001
208209 else :
209210 policy = identity
@@ -387,7 +388,7 @@ class _PublisherBase(BaseModel):
387388 model_config = ConfigDict (alias_generator = to_snake )
388389
389390 kind : str
390- claims : dict [str , Any ] | None = None
391+ claims : Optional [ dict [str , Any ]] = None
391392
392393 def _as_policy (self ) -> VerificationPolicy :
393394 """Return an appropriate `sigstore.policy.VerificationPolicy` for this publisher."""
@@ -483,7 +484,7 @@ class GitHubPublisher(_PublisherBase):
483484 action.
484485 """
485486
486- environment : str | None = None
487+ environment : Optional [ str ] = None
487488 """
488489 The optional name GitHub Actions environment that the publishing
489490 action was performed from.
@@ -505,7 +506,7 @@ class GitLabPublisher(_PublisherBase):
505506 `bar` owned by group `foo` and subgroup `baz`.
506507 """
507508
508- environment : str | None = None
509+ environment : Optional [ str ] = None
509510 """
510511 The optional environment that the publishing action was performed from.
511512 """
@@ -531,7 +532,7 @@ def _as_policy(self) -> VerificationPolicy:
531532 return policy .AllOf (policies )
532533
533534
534- _Publisher = GitHubPublisher | GitLabPublisher
535+ _Publisher = Union [ GitHubPublisher , GitLabPublisher ]
535536Publisher = Annotated [_Publisher , Field (discriminator = "kind" )]
536537
537538
0 commit comments