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

Add type annotations to the project and run mypy on CI #11

Merged
merged 2 commits into from Jul 7, 2022
Merged

Add type annotations to the project and run mypy on CI #11

merged 2 commits into from Jul 7, 2022

Conversation

jdufresne
Copy link
Contributor

This helps library consumers ensure that they are using the provided API
correctly. The project includes a py.typed file for PEP-561 compliance.

This also helps ensure internal correctness and consistency. mypy also
runs on the tests, to demonstrate the test cases are representative and
real use cases.

Type checking will run on all pull requests through GitHub actions and
pre-commit.

Copy link
Member

@hugovk hugovk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!

@@ -40,6 +40,7 @@ project_urls =
[options]
packages = find:
python_requires = >=3.7
include_package_data = true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this do?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this line, the py.typed file will not be installed to the Python site-packages directory.

Observe:

$ cd termcolor
$ pip install .
$ ls ~/.virtualenvs/termcolor/lib/python3.9/site-packages/termcolor/
... should include py.typed

Adjust the ls to be your virtualenv.

The py.typed file is necessary for PEP-561 compliance. More detail at:
https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-library-stubs-or-py-typed-marker

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good stuff, thanks!

def colored(text, color=None, on_color=None, attrs=None):
def colored(
text: str,
color: Optional[str] = None,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use from __future__ import annotations and do things like this?

Suggested change
color: Optional[str] = None,
color: str | None = None,

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea! Applied this suggestion in the latest revision.

@hugovk hugovk added the changelog: Added For new features label Jul 6, 2022
This helps library consumers ensure that they are using the provided API
correctly. The project includes a py.typed file for PEP-561 compliance.

This also helps ensure internal correctness and consistency. mypy also
runs on the tests, to demonstrate the test cases are representative and
real use cases.

Type checking will run on all pull requests through GitHub actions and
pre-commit.
@codecov
Copy link

codecov bot commented Jul 7, 2022

Codecov Report

Merging #11 (50eb6f4) into main (5e7356e) will not change coverage.
The diff coverage is 100.00%.

@@            Coverage Diff            @@
##              main       #11   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            3         3           
  Lines           65        70    +5     
=========================================
+ Hits            65        70    +5     
Flag Coverage Δ
macos-latest 100.00% <100.00%> (ø)
ubuntu-latest 100.00% <100.00%> (ø)
windows-latest 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/termcolor/__init__.py 100.00% <100.00%> (ø)
src/termcolor/termcolor.py 100.00% <100.00%> (ø)
tests/test_termcolor.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5e7356e...50eb6f4. Read the comment docs.

@hugovk hugovk merged commit 5f5016a into termcolor:main Jul 7, 2022
@hugovk
Copy link
Member

hugovk commented Jul 7, 2022

Thank you!

@jdufresne jdufresne deleted the mypy branch July 9, 2022 14:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog: Added For new features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants