Skip to content

Commit 5cb06e9

Browse files
committed
Update devdocs with more details about type hinting, especially deprecations
1 parent 00afcc0 commit 5cb06e9

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

doc/devel/coding_guide.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,8 @@ will run on all supported platforms and versions of Python.
350350

351351
- If *Linting* fails, you have a code style issue, which will be listed
352352
as annotations on the pull request's diff.
353+
- If *Mypy* or *Stubtest* fails, you have inconsistency in type hints, which
354+
will be listed as annotations in the diff.
353355
- If a GitHub Actions or AppVeyor run fails, search the log for ``FAILURES``.
354356
The subsequent section will contain information on the failed tests.
355357
- If CircleCI fails, likely you have some reStructuredText style issue in

doc/devel/contribute.rst

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,8 @@ Introducing
345345
- Use ``_api.warn_deprecated()`` for general deprecation warnings
346346
- Use the decorator ``@_api.deprecated`` to deprecate classes, functions,
347347
methods, or properties
348+
- Use the decorator ``@_api.deprecate_privatize_attribute`` to deprecate
349+
attributes while keeping the internal private version.
348350
- To warn on changes of the function signature, use the decorators
349351
``@_api.delete_parameter``, ``@_api.rename_parameter``, and
350352
``@_api.make_keyword_only``
@@ -354,6 +356,23 @@ Introducing
354356

355357
You can use standard rst cross references in *alternative*.
356358

359+
3. Make appropriate changes to the type hints in the associated `.pyi` file.
360+
The general guideline is to match runtime reported behavior.
361+
362+
- Items marked with ``@_api.deprecated`` or ``@_api.deprecate_privatize_attribute``
363+
are generally kept during the expiry period, and thus no changes are needed on
364+
introduction.
365+
- Items decorated with ``@_api.rename_parameter`` or ``@_api.make_keyword_only``
366+
report the *new* (post deprecation) signature at runtime, and thus *should* be
367+
updated on introduction.
368+
- Items decorated with ``@_api.delete_parameter`` should include a default value hint
369+
for the deleted parameter, even if it did not previously have one (e.g.
370+
``param: <type> = ...``). Even so, the decorator changes the default value to a
371+
sentinel value which should not be included in the type stub. Thus, Mypy Stubtest
372+
needs to be informed of the inconsistency by placing the method into
373+
``ci/mypy-stubtest-allowlist.txt`` under a heading indicating the deprecation
374+
version number.
375+
357376
Expiring
358377
~~~~~~~~
359378

@@ -365,6 +384,19 @@ Expiring
365384
information. For the content, you can usually copy the deprecation notice
366385
and adapt it slightly.
367386
2. Change the code functionality and remove any related deprecation warnings.
387+
3. Make appropriate changes to the type hints in the associated `.pyi` file.
388+
389+
- Items marked with ``@_api.deprecated`` or ``@_api.deprecate_privatize_attribute``
390+
are to be removed on expiry.
391+
- Items decorated with ``@_api.rename_parameter`` or ``@_api.make_keyword_only``
392+
will have been updated at introduction.
393+
- Items decorated with ``@_api.delete_parameter`` will need to be updated to the
394+
final signature, in the same way as the ``.py`` file signature is updated.
395+
The entry in ``ci/mypy-stubtest-allowlist.txt`` should be removed.
396+
- Any other entries in ``ci/mypy-stubtest-allowlist.txt`` under a versions
397+
deprecations should be double checked, as only ``delete_parameter`` should normally
398+
require that mechanism for deprecation. For removed items that were not in the stub
399+
file, only deleting from the allowlist is required.
368400

369401
Adding new API
370402
--------------
@@ -391,6 +423,7 @@ New modules and files: installation
391423
* If you have added new files or directories, or reorganized existing
392424
ones, make sure the new files are included in the match patterns in
393425
in *package_data* in :file:`setupext.py`.
426+
* New modules *may* be typed inline or using parallel stub file like existing modules.
394427

395428
C/C++ extensions
396429
----------------

0 commit comments

Comments
 (0)