Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hello!
I am a long-time user of markovify, and my most recent project has involved a lot of interacting with Chain internals. I'm used to being able to know things' argument and return types in my IDE, but markovify doesn't have type annotations, and lately I've been really butting up against that.
Well, one thing led to another, and I ended up adding type annotations to the entire package.
Here is what I have, after cleaning it up a little and making sure it works in the range of Python versions I am aware that markovify supports. Please take a look.
make format
returns no changesmake lint
returns no changesThe whole thing is type annotated. These are the changes made beside pure type annotations:
typing_extensions
is added as a dev dependency. No new runtime dependencies are added, and this is not imported at runtime.pytest-cov
code coverage decreased slightly due to the addition of some code that only runs while type checking, and anassert_never()
to appease Pylance at a certain unreachable line.cast_not_none()
helper function added tochain.py
andtext.py
.words
andcff
are different types and that it's always just those two items inside it.chain.compile_next()
's return type is changed accordingly, and logic was added tofrom_json()
to convert a rehydrated, compiled model's Nexts to tuples.One alternative could be to change compiled Nexts back to a list and say it can hold either lists of ints or lists of strings, and then cast the elements as they're used (like in
move()
).Chain
andText
's constructors to ensure that at least one source of data is provided (e.g., thatmodel
is provided ifcorpus
is not).