mirror of
https://github.com/status-im/PyGithub.git
synced 2026-08-31 10:51:14 +00:00
Use typing_extensions for TypedDict (#2592)
This commit is contained in:
@@ -20,26 +20,24 @@
|
||||
# #
|
||||
################################################################################
|
||||
|
||||
import sys
|
||||
import typing
|
||||
from typing import Union
|
||||
|
||||
from typing_extensions import TypedDict
|
||||
|
||||
import github.GithubObject
|
||||
import github.NamedUser
|
||||
|
||||
if sys.version_info >= (3, 8):
|
||||
# TypedDict is only available in Python 3.8 and later
|
||||
class SimpleCredit(typing.TypedDict):
|
||||
"""
|
||||
A simple credit for a security advisory.
|
||||
"""
|
||||
|
||||
login: typing.Union[str, "github.NamedUser.NamedUser"]
|
||||
type: str
|
||||
class SimpleCredit(TypedDict):
|
||||
"""
|
||||
A simple credit for a security advisory.
|
||||
"""
|
||||
|
||||
else:
|
||||
SimpleCredit = typing.Dict[str, typing.Any]
|
||||
login: Union[str, "github.NamedUser.NamedUser"]
|
||||
type: str
|
||||
|
||||
Credit = typing.Union[SimpleCredit, "RepositoryAdvisoryCredit"]
|
||||
|
||||
Credit = Union[SimpleCredit, "RepositoryAdvisoryCredit"]
|
||||
|
||||
|
||||
class RepositoryAdvisoryCredit(github.GithubObject.NonCompletableGithubObject):
|
||||
|
||||
@@ -20,42 +20,35 @@
|
||||
# #
|
||||
################################################################################
|
||||
|
||||
import sys
|
||||
import typing
|
||||
from typing import List
|
||||
from typing import List, Optional, Union
|
||||
|
||||
from typing_extensions import NotRequired, TypedDict
|
||||
|
||||
import github.GithubObject
|
||||
import github.RepositoryAdvisoryVulnerabilityPackage
|
||||
|
||||
if sys.version_info >= (3, 8):
|
||||
# TypedDict is only available in Python 3.8 and later
|
||||
class SimpleAdvisoryVulnerabilityPackage(typing.TypedDict):
|
||||
"""
|
||||
A simple package in an advisory.
|
||||
"""
|
||||
|
||||
ecosystem: str
|
||||
name: typing.Optional[str] # TODO: Python 3.11 make 'NotRequired'
|
||||
class SimpleAdvisoryVulnerabilityPackage(TypedDict):
|
||||
"""
|
||||
A simple package in an advisory.
|
||||
"""
|
||||
|
||||
class SimpleAdvisoryVulnerability(typing.TypedDict):
|
||||
"""
|
||||
A simple vulnerability in a security advisory.
|
||||
"""
|
||||
ecosystem: str
|
||||
name: NotRequired[Optional[str]]
|
||||
|
||||
package: SimpleAdvisoryVulnerabilityPackage
|
||||
patched_versions: typing.Optional[str] # TODO: Python 3.11 make 'NotRequired'
|
||||
vulnerable_functions: typing.Optional[
|
||||
List[str]
|
||||
] # TODO: Python 3.11 make 'NotRequired'
|
||||
vulnerable_version_range: typing.Optional[
|
||||
str
|
||||
] # TODO: Python 3.11 make 'NotRequired'
|
||||
|
||||
else:
|
||||
SimpleAdvisoryVulnerabilityPackage = typing.Dict[str, typing.Any]
|
||||
SimpleAdvisoryVulnerability = typing.Dict[str, typing.Any]
|
||||
class SimpleAdvisoryVulnerability(TypedDict):
|
||||
"""
|
||||
A simple vulnerability in a security advisory.
|
||||
"""
|
||||
|
||||
AdvisoryVulnerability = typing.Union[
|
||||
package: SimpleAdvisoryVulnerabilityPackage
|
||||
patched_versions: NotRequired[Optional[str]]
|
||||
vulnerable_functions: NotRequired[Optional[List[str]]]
|
||||
vulnerable_version_range: NotRequired[Optional[str]]
|
||||
|
||||
|
||||
AdvisoryVulnerability = Union[
|
||||
SimpleAdvisoryVulnerability, "RepositoryAdvisoryVulnerability"
|
||||
]
|
||||
|
||||
@@ -83,14 +76,14 @@ class RepositoryAdvisoryVulnerability(github.GithubObject.NonCompletableGithubOb
|
||||
return self._patched_versions.value
|
||||
|
||||
@property
|
||||
def vulnerable_functions(self) -> typing.Optional[List[str]]:
|
||||
def vulnerable_functions(self) -> Optional[List[str]]:
|
||||
"""
|
||||
:type: list of string
|
||||
"""
|
||||
return self._vulnerable_functions.value
|
||||
|
||||
@property
|
||||
def vulnerable_version_range(self) -> typing.Optional[str]:
|
||||
def vulnerable_version_range(self) -> Optional[str]:
|
||||
"""
|
||||
:type: string
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user