Add type hints#159
Conversation
|
Thanks for this contribution — stub coverage is thorough and the approach ( Bugs: incorrect stub signatures
Build configuration bug
Re: your note about dropping legacy Python support — that's on my radar. I'm going to open a separate PR to update the CI matrix (3.7 and 3.8 checks are failing anyway, and we're missing 3.12/3.13). Once that lands, if you'd like to follow up with a simplified version of these stubs using inline annotations and |
|
FYI, I just merged a separate PR (#160) that drops legacy Python support and sets 3.10 as the minimum version. This means you can simplify the stubs if you'd like — inline annotations directly in the source, |
|
I went ahead and cleaned out the Python 2 cruft in #161 |
|
@derek73 Thank you for the quick response. Sorry I messed up some hints in the original pull request. I usually rely on mypy for detecting type issues, but it did not help here because the hints were separated from the code. I have merged the type annotations with the code now. This also required some minor changes. I also removed code aimed at Python 2 compatibility, as well as some code that seemed dead. I added review comments to highlight this. See the descriptions of the individual commits for more information. Regarding your comment about Additionally, I removed |
0c48fae to
3203d0f
Compare
This includes a build system specification (PEP 518) and essential metadata (PEP 621). This configuration is needed for modern tooling. Migrate dev-dependencies.txt to pyproject.toml and add ruff and mypy. Also add a PEP 561 py.typed marker and a .python-version file.
The changes are mostly related to unicode and conditional imports.
This also required some refactoring: * I removed some code that seemed dead. * I created a subclass of TupleManager for regexes with a fallback. When accessing regexes previously, it was possible to get None. * I had to move all setter next to their getters due to a bug in mypy. See python/mypy#1465
The test was removed because it had no assertions, but it was covering string output for UTF-8 names parsed from comma format. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Moves all package metadata into pyproject.toml and extracts VERSION into a minimal _version.py so setuptools can read it without importing the full package, removing the self-referential build dependency. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replace `python setup.py sdist bdist_wheel` with `python -m build` and update the editable install URL to use https and modern pip syntax. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
dependency-groups (PEP 735) require pip>=24.2; pinning ensures the upgrade step meets that minimum before the dev install runs. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Using = [] on class-level attributes creates a single shared list instance across all HumanName instances. Any direct mutation (e.g. hn.first_list.append(...)) on an instance created without a full_name would corrupt the default for all subsequent instances. Both code paths in __init__ (parse_full_name and the per-attribute setters) always initialize these as instance-level lists, so the class-level defaults were never needed — only the type annotations are. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
In the latest commits I made a few changes on top of this PR: Restored Dropped Pinned Fixed mutable class-level list defaults — |
|
@v-- please review the changes I made and confirm everything works as expected in your environment. |
|
@derek73 The changes seem reasonable and the tests on my project utilizing |
Add tests for two code paths flagged in review: - test_phd_extracted_without_comma: covers fix_phd() extracting "Ph. D." from names without a comma (e.g. "John Smith Ph. D.") - test_roman_numeral_suffix_not_in_suffix_list: covers the is_roman_numeral(nxt) branch for VI-X, which are not in the suffix word lists and so are not caught by are_suffixes() first Other changes: - Replace list[T]() constructor style with typed annotations (list: T = []) in parser.py — same runtime behavior, idiomatic Python - Add LGPL license classifier to pyproject.toml (was present in setup.py) - Note pip >= 24.1 requirement for --group dev in CONTRIBUTING.md and AGENTS.md Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
thanks for the contribution! I will go ahead and merge it. I will try to publish a new version to pypi in the next few days. |
I added type hints (PEP 561) for the project. As far as I understood, the project insists on Python 2 compatibility, so I had to add the hints in stub files (
.pyi). These stubs, as well as the requiredpy.typedmarker file, get included in setuptools' builds.I have added a
pyproject.tomlfile with a standardized (PEP 517) build configuration. For this, I have set a low version of setuptools (v39.2.0) --- that last that supports Python 3.2 --- to avoid breaking compatibility.For details, see the individual commits.
PS: If you decide to drop support for legacy Python versions (i.e. anything below 3.10), the type hints can be simplified (PEP 585 and possibly PEP 612) and merged into the source itself. This will also allow simplifying the project configuration (i.e. drop setup.py/MANIFEST.in and use standardized version/dependency management).