chiark / gitweb /
documentation/python: adapt builtin method filters to changes in 3.11+.
authorVladimír Vondruš <mosra@centrum.cz>
Sat, 14 Sep 2024 22:11:23 +0000 (00:11 +0200)
committerVladimír Vondruš <mosra@centrum.cz>
Sat, 14 Sep 2024 23:48:41 +0000 (01:48 +0200)
documentation/python.py

index 122f5ef094f158c145204ca18a599da21c199b27..7c54232247329fe985483067135f878692051e0b 100755 (executable)
@@ -495,10 +495,30 @@ def crawl_class(state: State, path: List[str], class_):
                     # are added by typing.Generic on Py3.7+. Like above, can't
                     # use isinstance(object, Generic) because "Class
                     # typing.Generic cannot be used with class or instance
-                    # checks" and there's nothing else to catch on, so this
-                    # filters out all undocumented cases of these two
-                    if sys.version_info >= (3, 7) and name in ['__init_subclass__', '__class_getitem__'] and not object.__doc__:
-                        continue
+                    # checks"
+                    if sys.version_info >= (3, 7) and name == '__init_subclass__':
+                        # Before 3.12 it's completely undocumented and there's
+                        # nothing else to catch on, so this filters out all
+                        # undocumented cases
+                        if sys.version_info < (3, 12) and not object.__doc__:
+                            continue
+                        # https://github.com/python/cpython/blame/401fff7423ca3c8bf1d02e594edfd1412616a559/Objects/typevarobject.c#L2175
+                        if object.__doc__ == "Function to initialize subclasses.":
+                            continue
+                    if sys.version_info >= (3, 7) and name == '__class_getitem__':
+                        # Before 3.11 it's completely undocumented and there's
+                        # nothing else to catch on, so this filters out all
+                        # undocumented cases
+                        if sys.version_info < (3, 11) and not object.__doc__:
+                            continue
+                        # In 3.11 they OTOH get something very unique,
+                        # especially the markdown-like formatting
+                        # https://github.com/python/cpython/pull/31021
+                        # In 3.12 the extra spaces are removed
+                        if sys.version_info >= (3, 12) and object.__doc__.startswith("Parameterizes a generic class.\n\nAt least, parameterizing a generic class is the *main* thing"):
+                            continue
+                        if sys.version_info >= (3, 11) and object.__doc__.startswith("Parameterizes a generic class.\n\n        At least, parameterizing a generic class is the *main* thing"):
+                            continue
                     # ... or are auto-generated by attrs
                     if state.config['ATTRS_COMPATIBILITY']:
                         # All methods generated by attrs 20.1+ have a generic