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.
Resolve #210
This adds a type hinting stub file, src/init.pyi, which includes type hinted function signatures for the public functions of the packages. It also includes the
py.typed
file as a marker saying that type hinting information is available from the package.The problem
Currently when running
mypy
on a python source file that importspyperclip
will result in a type checking errorThere are ways that users can work around or ignore the error, but having to do so increases the chances that users will not type check their own code as well as they otherwise would.
The fix
We create a stub with correct type hinting and add a py.typed marker.
The relevant PEPs are 484 and 561.
With the fixed version:
Decisions made and their rationales
Maintain backwards compatibility.
paperclip must continue to work out of the box with all of the source published with Al Swiegart's books and material. Only those who seek to run static type checkers on code that imports pyperclip should notice any change. This is why the type hints are provided in the form of a PEPs 484 and 561 stub file.
__all__
functions instead of all functionsThe stub file includes signatures for all and only those listed in
__all__
functions provided by the module. This seems fully in line with the intention of__all__
timeout
is a float.Although most usages of timeout will be int's time, a float is maximally permissive while remaining compatible with the return type of
time.time()
Text in
py.typed
The existence of a
py.typed
file (PEP 561) is used to tell type checkers that there istype hinting information available. The file may be empty, but because the type hints are
in a stub file instead of in line in the source, I added some text in that file to help
humans find the type hinting information.
Before releasing
This PR does not touch the change log nor the version information. Those ought to be handled by the package maintainer.