-
Notifications
You must be signed in to change notification settings - Fork 84
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
Add stubs for clingo python module. #212
Closed
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I had to rename clingo.Tuple to clingo.Tuple_ because the name clashed with the name of the type annotation. Since the name Tuple is so general, renaming is probably the better strategy. The main thing that is still missing is to generate the stubs for the clingo.ast module to get rid of the last error messages. Even replacing those with typing.Any might work. Otherwise, some minor error message with mypy are left, which can be fixed by updating the type signatures.
mypy runs without errors on the generated stubs now. The only thing that is left is to refine the type annotations in the docstrings a bit. The main task is to get some nice base class for enumerations.
This replaces the too specific List with Sequence or Iterable depending on the context.
rkaminsk
added a commit
that referenced
this pull request
Apr 29, 2020
This commit refines type annotations in the clingo module and adds a script to generate stub files from the docstrings. The stub files can be used with systems like mypy. This commit also hides the Slice class be calling it _Slice and renames Tuple to Tuple_ so that it does not clash with the typing.Tuple.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This pull request continues the work in #188 to add stubs for clingo's python module. The stubs are generated from the information in the docstrings and can be updated with the
scratch/mypy.py
script.With this a python program using the clingo module can be type checked. For example running
mypy
on the programin file
test.py
results inbecause
clingo.Number(10)
should be used instead.List
where just anIterable
is required. This has to be fixed to make annotations usable in practice.There might be more issues regarding annotations because it is the first time that they are really used but this is probably best fixed in future commits when type checking real projects.