gijzelaerr / python-snap7

A Python wrapper for the snap7 PLC communication library
http://python-snap7.readthedocs.org/
MIT License
643 stars 246 forks source link

Use correct typing #372

Closed debauer closed 4 months ago

debauer commented 2 years ago

You use typing -> Great You return the wrong Type -> Not so Great You use strange typing -> okey but not Great

Examples: wrong use: util get_byte returns int, is typed as bytes strange use: util set_byte wants int no use: some return types and some arguments are not typed

Possible Solution: enforce mypy

Better possible Solution: use poetry, pylint, black (or similar tools) and enforce it in your pipeline

if you want i can participate and create a PR, but it can take some time.

swamper123 commented 2 years ago

Thanks for the hint. PRs are always welcomed :)

gijzelaerr commented 2 years ago

we already use mypy and flake8:

https://github.com/gijzelaerr/python-snap7/tree/master/.github/workflows

debauer commented 2 years ago

Okey. I'm to biased from my default config. default mypy is to lazy and imho useless. It enforce nothing. It only checks what you have typed. Not what you not have typed. Enforce it and you will never have typing problems at the runtime. Than you can't return an int if you typed the return as bytes.

My pyproject.toml contains:

warn_unused_configs = true
warn_unused_ignores = true
warn_redundant_casts = true
warn_no_return = true

no_implicit_optional = true
warn_unreachable = true
disallow_untyped_defs = true
disallow_incomplete_defs = true
# disallow_any_explicit = true
disallow_any_generics = true
disallow_untyped_calls = true

for nicer output:


# output style configuration
show_column_numbers = true
show_error_codes = true
pretty = true
``
gijzelaerr commented 4 months ago

i think we fixed the typing issues.