nvdlib
nvdlib copied to clipboard
Support for Python type hints
Hi @vehemont. Thank you for this excellent library 😁
Have you considered adding type hints to function parameters, return values, and class attributes? Something along the way like this:
def searchCVE(
cpeName: str=None,
cveId: str=None,
...
) -> CVE:
Hi,
I have thought about it but always decided against it. Since you have asked, I committed some type hints in 3fdd3f88ecc6ca05adcecc9fc65a2b0304c7630e. Is this what you had in mind?
Thanks
Hi! Thank you for your quick changes. This is already very useful.
One of my biggest advantages would be if the return type is a defined object.
def searchCVE(...) -> CVE:
@dataclass
class CVE:
descriptions: [Description]
# ...
@dataclass
class Description
lang: str
value: str
Also, I saw the usage of Tuple[str, datetime]
for fields like modification or publication dates.
lastModStartDate: Tuple[str, datetime] = None,
lastModEndDate: Tuple[str, datetime] = None,
Shouldn't this be a |
instead of Tuple[str, datetime]
because the type should either be a string
or a datetime
object:
lastModStartDate: str | datetime = None,
lastModEndDate: str | datetime = None,
The library is amazing, but having to suppress strict type checking on every call to the library can be a hassle. You mentioned you've “decided against it”. Does that mean PRs that enhance the type hints throughout the code are unwelcome? I'd love to contribute.
The library is amazing, but having to suppress strict type checking on every call to the library can be a hassle. You mentioned you've “decided against it”. Does that mean PRs that enhance the type hints throughout the code are unwelcome? I'd love to contribute.
Please feel free to submit any PRs for type hints. I have not had the time to do research to learn proper type hints. My original statement was negligent and uninformed at that time, but since this issue was opened I have been trying to learn and implement them, just have not had time. In that original statement, I meant that when I was creating NVDLib I didn't think they would be useful. I can see how useful they are in documentation so I am in full support of adding type hints.