VirusTotal / vt-py

The official Python 3 client library for VirusTotal
https://virustotal.github.io/vt-py/
Apache License 2.0
531 stars 121 forks source link

refactor: add type hints #159

Closed ninoseki closed 1 year ago

ninoseki commented 1 year ago

I re-created #43 because it becomes too old.

I believe adding type hints enhances vt-py's user experience. So I'd appreciate if you could give your time to review this PR.

For example,

Before

Screenshot 2023-09-09 at 9 30 28

obj from the iterator is Unknown.

After

Screenshot 2023-09-09 at 9 29 51

obj from the iterator is Object.

Thus IDE can suggest auto-completion.

Screenshot 2023-09-09 at 9 30 13
plusvic commented 1 year ago

I had to revert this change because the test suite started failing. First it was the linter:

Run pylint --rcfile pylintrc vt/ tests examples/
************* Module vt.client
vt/client.py:382:12: E[11](https://github.com/VirusTotal/vt-py/actions/runs/6129601871/job/16637863581#step:5:12)36: Value 'list' is unsubscriptable (unsubscriptable-object)
vt/client.py:404:[12](https://github.com/VirusTotal/vt-py/actions/runs/6129601871/job/16637863581#step:5:13): E1[13](https://github.com/VirusTotal/vt-py/actions/runs/6129601871/job/16637863581#step:5:14)6: Value 'list' is unsubscriptable (unsubscriptable-object)

I thought it was just a linting issue, but after disabling the unsubscriptable-object, it started failing while running the tests:

tests/test_iterator.py:19: in <module>
    import vt
vt/__init__.py:17: in <module>
    from .client import *
vt/client.py:177: in <module>
    class Client:
vt/client.py:385: in Client
    sleep_time: int = 20
E   TypeError: 'type' object is not subscriptable

I'm not sure what's happening here, the error message is quite confusing.

ninoseki commented 1 year ago

@plusvic Sorry it's totally my bad that I didn't test the PR with Python 3.7 and didn't apply pylint in tests directory. (I just did pylint vt/) I fixed the issue my PR has and now all tests are green. Is it okay to re-create PR again?

Screenshot 2023-09-09 at 18 49 16 (https://github.com/ninoseki/vt-py/actions/runs/6130207220)

mgmacias95 commented 1 year ago

hello @ninoseki,

Please, recreate the PR.

Thanks!

ninoseki commented 1 year ago

Thanks I re-created the PR as #161.