Skip to content

fix(abstract): stop relying on Cython resolving __NAME from class scope - #761

Open
mario4tier wants to merge 1 commit into
devfrom
fix/abstract-name-mangling-warnings
Open

fix(abstract): stop relying on Cython resolving __NAME from class scope#761
mario4tier wants to merge 1 commit into
devfrom
fix/abstract-name-mangling-warnings

Conversation

@mario4tier

Copy link
Copy Markdown
Member

Cython emits 58 warnings on every build of this repo, all one kind:

warning: talib/_abstract.pxi:35:4: Global name __PANDAS_SERIES matched from within
class scope in contradiction to Python 'class private name' rules. This may change
in a future release.

The Function class reads seven module globals whose leading double underscore
makes them mangling-eligible. Python's own rules say those references should
resolve to _Function__PANDAS_SERIES and raise NameError; Cython resolves them
to the module global instead, and warns that it may stop doing so. Dropping one
underscore makes the code mean what it already does.

renamed __PANDAS_SERIES __PANDAS_DATAFRAME __POLARS_SERIES __POLARS_DATAFRAME __ARRAY_TYPES __INPUT_ARRAYS_TYPES __INPUT_PRICE_SERIES_DEFAULTS
untouched __TA_FUNCTION_NAMES__ — trailing underscores put it outside the mangling rule, and it is public

tools/generate_stream.py referenced them too, so talib/_stream.pxi is
regenerated. Three hanging-indent blocks re-aligned by one column.

Cython warnings: 58 → 0. gcc: 0 before, 0 after.

Nothing else moves

  • dir() of talib, talib._ta_lib, talib.abstract and talib.stream, plus
    Function.info / .parameters / .function_flags, diffed before and after:
    the entire difference is those seven names in talib._ta_lib.
  • The generated _ta_lib.c, regenerated with the pinned Cython 3.2.8 and
    normalised for the rename, differs in 38 lines — all of them the interned
    string table: the packed identifier blob, its length index, the
    content-addressed __pyx_kp_b_* macro names, and the byte count
    (111563111555). No function body, no ABI, no code path, so performance
    is identical by construction.
  • 1697 tests pass; python-dev.py check green on all four steps, including
    "regenerating must change nothing" and the no-Cython sdist build.

The one thing that technically changes for an outside caller is that
talib._ta_lib.__PANDAS_SERIES no longer exists. It is dunder-prefixed, absent
from __all__ and undocumented — private by every convention — but it is a name
that existed before.

Cython emitted 58 warnings, all of the form

  Global name __PANDAS_SERIES matched from within class scope in contradiction
  to Python 'class private name' rules. This may change in a future release.

The Function class reads seven module globals whose leading double underscore
makes them mangling-eligible, so Python's own rules say those references should
resolve to _Function__PANDAS_SERIES and fail. Cython resolves them to the module
global instead and warns that it may stop. Dropping one underscore makes the
code mean what it already did.

The seven are private by every convention -- absent from __all__, undocumented --
and __TA_FUNCTION_NAMES__ is untouched: its trailing underscores put it outside
the mangling rule. tools/generate_stream.py referenced them too, so _stream.pxi
is regenerated.

Nothing else moves. dir() of talib, talib._ta_lib, talib.abstract and
talib.stream differs only by those seven names, and the generated C, normalised
for the rename, differs only in the interned string table -- no function body,
no ABI, no code path.
@mrjbq7

mrjbq7 commented Sep 7, 2026

Copy link
Copy Markdown
Member

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants