Skip to content

Commit 86dda9b

Browse files
committed
fix: pre-3.13 compat?
Following where `__name__` used to be sourced from - python/cpython#101876
1 parent f3f79f3 commit 86dda9b

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

utils/check_api_reference.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
from __future__ import annotations
22

33
import inspect
4+
import string
45
import sys
6+
from inspect import isfunction
57
from pathlib import Path
68
from typing import Any
79
from typing import Iterator
@@ -11,13 +13,20 @@
1113
import narwhals as nw
1214
from narwhals.utils import remove_prefix
1315

16+
LOWERCASE = tuple(string.ascii_lowercase)
1417

15-
def _is_public_method_or_property(obj: Any) -> bool:
16-
return (
17-
(inspect.isfunction(obj) or isinstance(obj, property))
18-
and not obj.__name__[0].isupper()
19-
and obj.__name__[0] != "_"
20-
)
18+
if sys.version_info >= (3, 13):
19+
20+
def _is_public_method_or_property(obj: Any) -> bool:
21+
return (isfunction(obj) or isinstance(obj, property)) and obj.__name__.startswith(
22+
LOWERCASE
23+
)
24+
else:
25+
26+
def _is_public_method_or_property(obj: Any) -> bool:
27+
return (isfunction(obj) and obj.__name__.startswith(LOWERCASE)) or (
28+
isinstance(obj, property) and obj.fget.__name__.startswith(LOWERCASE)
29+
)
2130

2231

2332
def iter_api_reference_names(tp: type[Any]) -> Iterator[str]:

0 commit comments

Comments
 (0)