Part of the repository modernization effort.
Background
No module in bmemcached/ has type annotations. All type information lives in Sphinx docstring fields, for example bmemcached/protocol.py:239,288,363,409,452. A type checker cannot read these. Some are already stale.
bmemcached/client/mixin.py:153 holds one lone comment-style hint:
# type: (six.string_types, int) -> bool
No 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 the urlparse fallback.
bmemcached/compat.py:5 — import pickle as pickle # type: ignore.
The Python 2 cleanup issues delete both.
bmemcached/py.typed does not exist. Downstream mypy and pyright users cannot read this package's types. See PEP 561.
No mypy config exists. mypy.ini is absent. pyproject.toml holds no [tool.mypy] table.
Scope
Annotate the leaf modules only. Do not annotate bmemcached/protocol.py in this issue.
bmemcached/protocol.py is the core module. Its COMMANDS dict-of-dicts and its tuple response handling need a TypedDict or NamedTuple refactor before they type cleanly. That is separate work.
Plan
- Add an empty
bmemcached/py.typed file.
- Include
py.typed in the built package. Add [tool.setuptools.package-data] to pyproject.toml, or add the path to MANIFEST.in.
- Annotate
bmemcached/exceptions.py. It holds three classes.
- Annotate
bmemcached/utils.py. It holds one function.
- Annotate
bmemcached/client/constants.py. It holds constants only.
- Add
mypy to the test dependency group.
- Add a
[tool.mypy] table. Run --strict on those three files only.
- Wire the
mypy run into tox.ini.
Follow-up order for later issues
Annotate in this order after this issue lands:
bmemcached/client/mixin.py. It defines the shared NotImplementedError stubs that the other two clients override.
bmemcached/client/distributed.py and bmemcached/client/replicating.py.
bmemcached/protocol.py, with the TypedDict refactor.
Acceptance criteria
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 six removal 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.
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.