Skip to content
New issue

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

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

Already on GitHub? # to your account

feat: add type for high level api # 138 #139

Merged
merged 7 commits into from
Jul 30, 2024

Conversation

wangxin688
Copy link
Contributor

add type annotation for high level API

@wangxin688 wangxin688 changed the title feat: add type for high level api feat: add type for high level api # 138 Jul 25, 2024
@wangxin688
Copy link
Contributor Author

@carlkidcrypto since I'm not very sure about the type of value and if it's proper to add Literal type for value_type. I need your advice to implement related code. Also I found some code to check python version which is not needed anymore in compat.py?

@wangxin688
Copy link
Contributor Author

if the high level api type-hint is OK. I will try to make the whole python code well typed

@carlkidcrypto carlkidcrypto enabled auto-merge (squash) July 26, 2024 00:02
@carlkidcrypto carlkidcrypto disabled auto-merge July 26, 2024 00:02
@carlkidcrypto
Copy link
Owner

carlkidcrypto commented Jul 26, 2024

@carlkidcrypto since I'm not very sure about the type of value and if it's proper to add Literal type for value_type. I need your advice to implement related code. Also I found some code to check python version which is not needed anymore in compat.py?

@wangxin688 yes, you can remove lines 1,3,5,8,17-27 from compat.py.

Setup.cfg should enforce the python3 versions we support.

https://github.com/carlkidcrypto/ezsnmp/blob/main/ezsnmp%2Fcompat.py

As for value_type I am still looking into it.

In the meantime tests are failing for Python 3.8

ImportError while loading conftest '/home/runner/work/ezsnmp/ezsnmp/tests/conftest.py'.
tests/conftest.py:7: in <module>
    import ezsnmp
ezsnmp/__init__.py:1: in <module>
    from .ez import (  # noqa
ezsnmp/ez.py:5: in <module>
    from .session import Session
ezsnmp/session.py:69: in <module>
    def validate_results(varlist: list[SNMPVariable]) -> None:
E   TypeError: 'type' object is not subscriptable

@wangxin688
Copy link
Contributor Author

@carlkidcrypto since I'm not very sure about the type of value and if it's proper to add Literal type for value_type. I need your advice to implement related code. Also I found some code to check python version which is not needed anymore in compat.py?

@wangxin688 yes, you can remove lines 1,3,5,8,17-27 from compat.py.

Setup.cfg should enforce the python3 versions we support.

https://github.com/carlkidcrypto/ezsnmp/blob/main/ezsnmp%2Fcompat.py

As for value_type I am still looking into it.

In the meantime tests are failing for Python 3.8

ImportError while loading conftest '/home/runner/work/ezsnmp/ezsnmp/tests/conftest.py'.
tests/conftest.py:7: in <module>
    import ezsnmp
ezsnmp/__init__.py:1: in <module>
    from .ez import (  # noqa
ezsnmp/ez.py:5: in <module>
    from .session import Session
ezsnmp/session.py:69: in <module>
    def validate_results(varlist: list[SNMPVariable]) -> None:
E   TypeError: 'type' object is not subscriptable

let me fix it. list should be replace with List in lower python version

@wangxin688
Copy link
Contributor Author

another proposal. it will be a good choice to add a pre-commit lint tool and use ruff as black alternative.
ruff is a superfast and full features static code check tool

@carlkidcrypto
Copy link
Owner

another proposal. it will be a good choice to add a pre-commit lint tool and use ruff as black alternative.
ruff is a superfast and full features static code check tool

Thanks for the proposal. We will stick with Black for now.

Black can be run too, just before you commit anything.

python3 -m black .

@carlkidcrypto
Copy link
Owner

Some tests keep failing on MacOS Python 3.8 and 3.11.

---------- coverage: platform darwin, python 3.9.13-final-0 ----------
Name                   Stmts   Miss  Cover   Missing
----------------------------------------------------
ezsnmp/__init__.py         4      0   100%
ezsnmp/compat.py           6      0   100%
ezsnmp/exceptions.py      17      0   100%
ezsnmp/ez.py              38      0   100%
ezsnmp/helpers.py          9      0   100%
ezsnmp/session.py        170      8    95%   278, 281, 382, 430, 471, 503, 540, 574
ezsnmp/utils.py           27      1    96%   48
ezsnmp/variables.py       20      0   100%
----------------------------------------------------
TOTAL                    291      9    97%

=========================== short test summary info ============================
FAILED tests/test_session.py::test_session_walk_all[sess_args0] - ezsnmp.exceptions.EzSNMPTimeoutError: timed out while connecting to remote host
FAILED tests/test_session.py::test_session_walk_all[sess_args1] - ezsnmp.exceptions.EzSNMPTimeoutError: timed out while connecting to remote host
FAILED tests/test_session.py::test_session_walk_all[sess_args2] - ezsnmp.exceptions.EzSNMPTimeoutError: timed out while connecting to remote host
FAILED tests/test_session.py::test_session_walk_all[sess_args3] - ezsnmp.exceptions.EzSNMPTimeoutError: timed out while connecting to remote host
FAILED tests/test_session.py::test_session_walk_all[sess_args4] - ezsnmp.exceptions.EzSNMPTimeoutError: timed out while connecting to remote host
======================== 5 failed, 306 passed in 39.41s ========================

@carlkidcrypto carlkidcrypto self-assigned this Jul 26, 2024
@carlkidcrypto carlkidcrypto added the enhancement New feature or request label Jul 26, 2024
Copy link
Owner

@carlkidcrypto carlkidcrypto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments.

@wangxin688
Copy link
Contributor Author

Some tests keep failing on MacOS Python 3.8 and 3.11.

---------- coverage: platform darwin, python 3.9.13-final-0 ----------
Name                   Stmts   Miss  Cover   Missing
----------------------------------------------------
ezsnmp/__init__.py         4      0   100%
ezsnmp/compat.py           6      0   100%
ezsnmp/exceptions.py      17      0   100%
ezsnmp/ez.py              38      0   100%
ezsnmp/helpers.py          9      0   100%
ezsnmp/session.py        170      8    95%   278, 281, 382, 430, 471, 503, 540, 574
ezsnmp/utils.py           27      1    96%   48
ezsnmp/variables.py       20      0   100%
----------------------------------------------------
TOTAL                    291      9    97%

=========================== short test summary info ============================
FAILED tests/test_session.py::test_session_walk_all[sess_args0] - ezsnmp.exceptions.EzSNMPTimeoutError: timed out while connecting to remote host
FAILED tests/test_session.py::test_session_walk_all[sess_args1] - ezsnmp.exceptions.EzSNMPTimeoutError: timed out while connecting to remote host
FAILED tests/test_session.py::test_session_walk_all[sess_args2] - ezsnmp.exceptions.EzSNMPTimeoutError: timed out while connecting to remote host
FAILED tests/test_session.py::test_session_walk_all[sess_args3] - ezsnmp.exceptions.EzSNMPTimeoutError: timed out while connecting to remote host
FAILED tests/test_session.py::test_session_walk_all[sess_args4] - ezsnmp.exceptions.EzSNMPTimeoutError: timed out while connecting to remote host
======================== 5 failed, 306 passed in 39.41s ========================

this is strange, assume it's not code error. as error says that it's timeout. this is the result I run test on linux:

collected 311 items                                                                                                                                                                                                 

 tests/test_auth_priv_v3.py ✓✓✓✓✓                                                                                                                                                                       2% ▎         
 tests/test_cache_v3.py ✓                                                                                                                                                                               2% ▎         
 tests/test_ez.py ✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓                     53% █████▍    
 tests/test_helpers.py ✓✓✓✓                                                                                                                                                                            55% █████▌    
 tests/test_session.py ✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓                                                        93% █████████▍
 tests/test_session_build_varlist.py ✓✓                                                                                                                                                                94% █████████▍
 tests/test_utils.py ✓✓✓✓✓✓                                                                                                                                                                            96% █████████▋
 tests/test_variables.py ✓✓✓✓✓✓✓✓✓✓✓✓✓                                                                                                                                                                100% ██████████

---------- coverage: platform linux, python 3.10.13-final-0 ----------
Name                   Stmts   Miss  Cover   Missing
----------------------------------------------------
ezsnmp/__init__.py         4      0   100%
ezsnmp/compat.py           6      0   100%
ezsnmp/exceptions.py      17      0   100%
ezsnmp/ez.py              47      0   100%
ezsnmp/helpers.py          9      0   100%
ezsnmp/session.py        170      8    95%   281, 284, 385, 433, 474, 506, 543, 577
ezsnmp/utils.py           27      1    96%   48
ezsnmp/variables.py       20      0   100%
----------------------------------------------------
TOTAL                    300      9    97%


Results (53.36s):
     311 passed

- introduce some delay so we don't DDos our own test snmp server.
@carlkidcrypto
Copy link
Owner

---------- coverage: platform darwin, python 3.9.6-final-0 -----------
Name                   Stmts   Miss  Cover   Missing
----------------------------------------------------
ezsnmp/__init__.py         4      0   100%
ezsnmp/compat.py           6      0   100%
ezsnmp/exceptions.py      17      0   100%
ezsnmp/ez.py              47      0   100%
ezsnmp/helpers.py          9      0   100%
ezsnmp/session.py        170      8    95%   281, 284, 385, 433, 474, 506, 543, 577
ezsnmp/utils.py           27      1    96%   48
ezsnmp/variables.py       20      0   100%
----------------------------------------------------
TOTAL                    300      9    97%


Results (33.58s):
     311 passed

ran tests on MacOS they pass as well, something must be up with the CI.

@carlkidcrypto carlkidcrypto merged commit c8fcaee into carlkidcrypto:main Jul 30, 2024
32 of 33 checks passed
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement New feature or request
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants