python-snap7 icon indicating copy to clipboard operation
python-snap7 copied to clipboard

Use correct typing

Open debauer opened this issue 2 years ago • 3 comments

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.

debauer avatar Jun 24 '22 11:06 debauer

Thanks for the hint. PRs are always welcomed :)

swamper123 avatar Jun 24 '22 11:06 swamper123

we already use mypy and flake8:

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

gijzelaerr avatar Jun 24 '22 12:06 gijzelaerr

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
``

debauer avatar Jun 24 '22 12:06 debauer

i think we fixed the typing issues.

gijzelaerr avatar May 02 '24 07:05 gijzelaerr