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

Some collected cleanups #435

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open

Some collected cleanups #435

wants to merge 14 commits into from

Conversation

MaxG87
Copy link
Contributor

@MaxG87 MaxG87 commented Jun 4, 2021

When I wanted to work on some bug that keeps nagging me, I noticed that support or Python 3.5 was dropped. I also noticed some minor negligencese I could not resist to improve.

This PR resolves these negligences and adds static analysis by mypy. Mypy mostly checks static types but can detect also some other problems like tatulogical conditions or unreachable code.

Please note that while complete this PR is also a kind of RFC. If it is accepted, I might add some more type hints and the related refactorings with further PRs. So feel free to nit-pick a lot here ;-).

The added type hints are required to prevent a mypy complaint later on.
The documentation of click.ParamType states that `ParamType.convert`
will never get a parameter `value` that is `None` [1]. Therefore, the entire
branching can be removed. With it, the implicit return of None is
removed too.

  [1]: https://click.palletsprojects.com/en/8.0.x/api/#click.ParamType.convert
A bit of guessing was involved. In one case a potential bug was
uncovered: If the raw string for `stop` was empty, the initialisation of
the stop time would have been skipped. This is fixed right ahead.
A classmethod `make_new` is introduced and used throughout the code.
This prepares rewriting the class to a typed NamedTuple.
Using typing.NamedTuple has plenty of advantages over
collections.namedtuple. The most important is that now HEADERS is not
required anymore for class construction.
Its relevant only in Python 2.7.
Now that all very obvious type problems are resolved, mypy can be used
in the static analysis part.
@MaxG87
Copy link
Contributor Author

MaxG87 commented Jun 9, 2021

I force pushed fixes for the overly long lines.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants