Skip to content

Strict type checking and py.typed#23

Merged
jaraco merged 11 commits intojaraco:mainfrom
Avasam:Strict-type-checking-and-py.typed
Feb 8, 2026
Merged

Strict type checking and py.typed#23
jaraco merged 11 commits intojaraco:mainfrom
Avasam:Strict-type-checking-and-py.typed

Conversation

@Avasam
Copy link
Contributor

@Avasam Avasam commented Feb 8, 2025

Closes #17

Ref: jaraco/skeleton#143

This is one of the untyped libs used by distutils and setuptools.

@Avasam Avasam force-pushed the Strict-type-checking-and-py.typed branch 7 times, most recently from a07a320 to f57c91c Compare February 8, 2025 02:42
@Avasam Avasam force-pushed the Strict-type-checking-and-py.typed branch 5 times, most recently from b2b5e84 to ef07488 Compare February 8, 2025 03:06
@Avasam Avasam force-pushed the Strict-type-checking-and-py.typed branch from ef07488 to 1e170b0 Compare June 20, 2025 17:09
@Avasam Avasam force-pushed the Strict-type-checking-and-py.typed branch from 74d635c to fd2301e Compare October 27, 2025 16:21
@Avasam Avasam force-pushed the Strict-type-checking-and-py.typed branch from fd2301e to 630fff0 Compare October 27, 2025 16:23
@jaraco jaraco closed this Feb 8, 2026
@jaraco jaraco reopened this Feb 8, 2026
@jaraco jaraco force-pushed the Strict-type-checking-and-py.typed branch from b33c388 to be6c64c Compare February 8, 2026 20:16

@ExceptionTrap(UnicodeDecodeError).passes
def is_decodable(value):
@ExceptionTrap(UnicodeDecodeError).passes # type: ignore[no-untyped-call, untyped-decorator] # jaraco/jaraco.context#15
Copy link
Owner

Choose a reason for hiding this comment

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

Sadly, this isn't working on mypy under PyPy.

FAILED jaraco/text/__init__.py::mypy - jaraco/text/__init__.py:205: error: Unused "type: ignore[untyped-decorator]...

Copy link
Owner

Choose a reason for hiding this comment

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

Interestingly, it passes for me locally.

Details
 jaraco.text main 🐚 tox -e pypy
.pkg-pypy310: install_requires> python -I -m pip install coherent.licensed 'setuptools>=77' 'setuptools_scm[toml]>=3.4.1'
.pkg-pypy310: _optional_hooks> python '/Users/jaraco/Library/Application Support/pipx/venvs/tox/lib/python3.13/site-packages/pyproject_api/_backend.py' True setuptools.build_meta
.pkg-pypy310: get_requires_for_build_editable> python '/Users/jaraco/Library/Application Support/pipx/venvs/tox/lib/python3.13/site-packages/pyproject_api/_backend.py' True setuptools.build_meta
.pkg-pypy310: build_editable> python '/Users/jaraco/Library/Application Support/pipx/venvs/tox/lib/python3.13/site-packages/pyproject_api/_backend.py' True setuptools.build_meta
pypy: install_package_deps> python -I -m pip install autocommand inflect 'jaraco.context>=4.1' jaraco.functools more_itertools 'mypy<1.19; platform_python_implementation == "PyPy"' 'pathlib2; python_version < "3.10"' 'pytest!=8.1.*,>=6' 'pytest-checkdocs>=2.4' pytest-cov 'pytest-enabler>=3.4' 'pytest-mypy>=1.0.1' 'pytest-ruff>=0.2.1; sys_platform != "cygwin"'
pypy: install_package> python -I -m pip install --force-reinstall --no-deps /Users/jaraco/code/jaraco/jaraco.text/.tox/.tmp/package/36/jaraco_text-4.0.1.dev56+g6a9b9bd06-0.editable-py3-none-any.whl
pypy: commands[0]> pytest
============================================================== test session starts ===============================================================
platform darwin -- Python 3.10.14[pypy-7.3.17-final], pytest-9.0.2, pluggy-1.6.0
cachedir: .tox/pypy/.pytest_cache
rootdir: /Users/jaraco/code/jaraco/jaraco.text
configfile: pytest.ini
plugins: mypy-1.0.1, ruff-0.5, checkdocs-2.14.0, enabler-3.4.0, typeguard-4.4.4, cov-7.0.0
collected 53 items                                                                                                                               

conftest.py ...                                                                                                                            [  5%]
docs/conf.py ...                                                                                                                           [ 11%]
jaraco/text/__init__.py ...........................                                                                                        [ 62%]
jaraco/text/layouts.py .....                                                                                                               [ 71%]
jaraco/text/show-newlines.py ....                                                                                                          [ 79%]
jaraco/text/strip-prefix.py ....                                                                                                           [ 86%]
jaraco/text/to-dvorak.py ...                                                                                                               [ 92%]
jaraco/text/to-qwerty.py ...                                                                                                               [ 98%]
. .                                                                                                                                        [100%]

================================================================ warnings summary ================================================================
conftest.py::mypy
  /opt/homebrew/Cellar/pypy3.10/7.3.17_1/libexec/lib/pypy3.10/configparser.py:694: EncodingWarning: 'encoding' argument not specified.
    encoding = io.text_encoding(encoding)

conftest.py::mypy
  /Users/jaraco/code/jaraco/jaraco.text/.tox/pypy/lib/pypy3.10/site-packages/mypy/modulefinder.py:979: EncodingWarning: 'encoding' argument not specified.
    with open(versions_path) as f:

conftest.py::mypy
  /Users/jaraco/code/jaraco/jaraco.text/.tox/pypy/lib/pypy3.10/site-packages/mypy/build.py:3583: EncodingWarning: 'encoding' argument not specified.
    with open(fnam, "w") as f:

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
====================================================================== mypy ======================================================================
Success: no issues found in 8 source files
================================================================= tests coverage =================================================================
_______________________________________________ coverage: platform darwin, python 3.10.14-final-0 ________________________________________________

Name                           Stmts   Miss  Cover   Missing
------------------------------------------------------------
conftest.py                        6      0   100%
docs/conf.py                      15      0   100%
jaraco/text/__init__.py          165      0   100%
jaraco/text/layouts.py             8      0   100%
jaraco/text/show-newlines.py      10      0   100%
jaraco/text/strip-prefix.py        6      0   100%
jaraco/text/to-dvorak.py           3      0   100%
jaraco/text/to-qwerty.py           3      0   100%
------------------------------------------------------------
TOTAL                            216      0   100%
=================================================== 53 passed, 3 warnings in 87.69s (0:01:27) ====================================================
  pypy: OK (99.52=setup[10.55]+cmd[88.97] seconds)
  congratulations :) (99.58 seconds)

Copy link
Owner

Choose a reason for hiding this comment

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

My guess is the untyped-decorator was added in a later mypy, but since mypy dropped support for PyPy (python/mypy#20454), it is now no longer compatible.

Copy link
Owner

Choose a reason for hiding this comment

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

It's not that the PyPy issue. And if it was, that wouldn't have explained why mine passed locally. I did try installing mypy<1.19 in my CPython install, but that had no effect (still passes).

Copy link
Owner

Choose a reason for hiding this comment

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

Oh, silly me. I wasn't on the PR branch. After switching to the PR branch, I'm able to replicate the failure.

Copy link
Owner

Choose a reason for hiding this comment

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

I tried adding in another ignore ("unused-ignore"), but now there's a new mypy error (still PyPy only):

jaraco/text/__init__.py:205: error: Untyped decorator makes function "is_decodable" untyped  [misc]
jaraco/text/__init__.py:205: note: Error code "misc" not covered by "type: ignore" comment

Copy link
Contributor Author

@Avasam Avasam Feb 8, 2026

Choose a reason for hiding this comment

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

If it's a pypy-only failure, that's odd.

But even if it's not, I'll take this opportunity to mention that I've also been pushing to stop running mypy on pypy for various reasons: flaky tests, randomly not matching an import-based error (likely due to differing dependencies), sporadic build failures, taking more CI time for a static non-runtime check that is already covered, etc: jaraco/skeleton#187

Copy link
Owner

Choose a reason for hiding this comment

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

In ab1de64, I suppressed those additional classes and now the tests are passing on mypy too.

Copy link
Owner

Choose a reason for hiding this comment

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

I've been pushing to stop running mypy on pypy

Probably a wise choice. I'd like to avoid making that change a blocker for this change, so I'll follow up on that later, now that I've found a workaround.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's funny you can ignore unused-ignore, I seem to remember this was causing a self-referential issue a long time ago !

@jaraco jaraco merged commit 6c25ce8 into jaraco:main Feb 8, 2026
15 checks passed
@Avasam Avasam deleted the Strict-type-checking-and-py.typed branch February 8, 2026 20:57
@Avasam
Copy link
Contributor Author

Avasam commented Feb 8, 2026

Thanks for the thorough review! Now that this is merged, my other 3 PRs have conflicts, but they are 3 suggestions for the same core issue. I'll let you think about your preferred approach before fixing conflicts.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fully type module then mark as py.typed

2 participants