Repository navigation
Add py.typed and annotate the leaf modules #275
Copy link
Copy link
Open
Labels
code-qualityCode quality, typing and defectsCode quality, typing and defectsmodernizationRepo modernization effortRepo modernization effort
Description
Activity
- addedmodernizationRepo modernization effortRepo modernization effortcode-qualityCode quality, typing and defectsCode quality, typing and defects
on Sep 8, 2026 Tracked in #277.
Deferred. This issue is not implemented in the current modernization run.
It depends on three pull requests that are open and not merged:
- feat: set the Python 3.10 floor and remove the Python 2 support layer #278 — sets the Python 3.10 floor and removes
sixandbmemcached/compat.py(closes Set the minimum supported Python version to 3.10 #265, Remove the six dependency and delete bmemcached/compat.py #266, Remove the remaining Python 2 idioms #267). This issue must not annotate code that pull request deletes. - chore: migrate packaging to PEP 621 and replace flake8 with ruff #279 — migrates packaging to a PEP 621
pyproject.toml(closes Migrate setup.py to a PEP 621 pyproject.toml #268, Replace flake8 with ruff and modernize pre-commit #269, Replace requirements_test.txt with a PEP 735 dependency group #270). This issue adds a[tool.mypy]table and amypyentry in the test dependency group. Both need that file to exist first. - fix: replace assert guards, add an exception message, and stop a password leak #282 — adds
MemcachedException.__str__and changes the shape of the exception classes (closes Fix five defects: assert guards, exception message, password leak, circular import #273). This issue annotatesbmemcached/exceptions.py.
Implement this issue after those three merge.
Two notes for whoever picks it up.
The two
# type: ignorecomments named in the issue body are already gone. #278 deletedbmemcached/compat.pyand replaced theurlparseimport fallback inbmemcached/protocol.pywith a directfrom urllib.parse import SplitResult.The lone comment-style hint at
bmemcached/client/mixin.py:153reads# type: (six.string_types, int) -> booltoday. #278 rewrites it to# type: (str, int) -> bool. Replace it with a real annotation in this issue.- feat: set the Python 3.10 floor and remove the Python 2 support layer #278 — sets the Python 3.10 floor and removes
Metadata
Metadata
Assignees
Labels
code-qualityCode quality, typing and defectsCode quality, typing and defectsmodernizationRepo modernization effortRepo modernization effort
Part of the repository modernization effort.
Background
No module in
bmemcached/has type annotations. All type information lives in Sphinx docstring fields, for examplebmemcached/protocol.py:239,288,363,409,452. A type checker cannot read these. Some are already stale.bmemcached/client/mixin.py:153holds one lone comment-style hint:# type: (six.string_types, int) -> boolNo other line in that file matches it.
Two type-checker comments exist. Both mark Python 2 code:
bmemcached/protocol.py:7,9—# type: ignore[import-not-found]on theurlparsefallback.bmemcached/compat.py:5—import pickle as pickle # type: ignore.The Python 2 cleanup issues delete both.
bmemcached/py.typeddoes not exist. Downstreammypyandpyrightusers cannot read this package's types. See PEP 561.No
mypyconfig exists.mypy.iniis absent.pyproject.tomlholds no[tool.mypy]table.Scope
Annotate the leaf modules only. Do not annotate
bmemcached/protocol.pyin this issue.bmemcached/protocol.pyis the core module. ItsCOMMANDSdict-of-dicts and its tuple response handling need aTypedDictorNamedTuplerefactor before they type cleanly. That is separate work.Plan
bmemcached/py.typedfile.py.typedin the built package. Add[tool.setuptools.package-data]topyproject.toml, or add the path toMANIFEST.in.bmemcached/exceptions.py. It holds three classes.bmemcached/utils.py. It holds one function.bmemcached/client/constants.py. It holds constants only.mypyto the test dependency group.[tool.mypy]table. Run--stricton those three files only.mypyrun intotox.ini.Follow-up order for later issues
Annotate in this order after this issue lands:
bmemcached/client/mixin.py. It defines the sharedNotImplementedErrorstubs that the other two clients override.bmemcached/client/distributed.pyandbmemcached/client/replicating.py.bmemcached/protocol.py, with theTypedDictrefactor.Acceptance criteria
bmemcached/py.typedexists and is empty.bmemcached/py.typed. Check withpython -m buildand an unzip of the wheel.bmemcached/exceptions.py,bmemcached/utils.py, andbmemcached/client/constants.pyhold full annotations.pyproject.tomlholds a[tool.mypy]table.mypy --strictpasses on those three files.tox.iniruns themypycommand.mypyis in the test dependency group.Files to change
bmemcached/py.typed(new),pyproject.toml,MANIFEST.in,bmemcached/exceptions.py,bmemcached/utils.py,bmemcached/client/constants.py,tox.ini.Order
Do the
sixremoval issue first. Do not annotate code that a later issue deletes.Do the defect-fix issue first. That issue adds
MemcachedException.__str__.Do the PEP 621 issue first. This issue changes
pyproject.toml.