Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Python type hints #32

Open
ammerzon opened this issue Oct 12, 2023 · 5 comments
Open

Support for Python type hints #32

ammerzon opened this issue Oct 12, 2023 · 5 comments
Assignees
Labels
enhancement New feature or request

Comments

@ammerzon
Copy link

ammerzon commented Oct 12, 2023

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:
@ammerzon ammerzon changed the title Add type hints Support for Python type hints Oct 12, 2023
@vehemont vehemont self-assigned this Oct 12, 2023
@vehemont
Copy link
Owner

Hi,

I have thought about it but always decided against it. Since you have asked, I committed some type hints in 3fdd3f8. Is this what you had in mind?

Thanks

@ammerzon
Copy link
Author

ammerzon commented Oct 15, 2023

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

@vehemont vehemont added the enhancement New feature or request label Oct 18, 2023
@ammerzon
Copy link
Author

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,

@MatheusCylo
Copy link

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.

@vehemont
Copy link
Owner

vehemont commented Jun 27, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants