Skip to content

Refactor pyconvert rule storage and API to scoped rules with explicit ordering and update conversions#802

Open
cjdoris wants to merge 4 commits into
v1from
codex/implement-new-pyconvert-rule-system
Open

Refactor pyconvert rule storage and API to scoped rules with explicit ordering and update conversions#802
cjdoris wants to merge 4 commits into
v1from
codex/implement-new-pyconvert-rule-system

Conversation

@cjdoris

@cjdoris cjdoris commented Jul 19, 2026

Copy link
Copy Markdown
Member

Motivation

  • Simplify and make pyconvert rules more explicit by giving each rule a scope and a deterministic ordering instead of a multipriority enum, enabling clearer matching semantics and easier high-priority insertion.
  • Update the existing conversion rules (numpy, ctypes, pandas, wrap, jlwrap) to the new API and ensure registration ordering is deterministic at package init.

Description

  • Reworked the pyconvert rule internals: PyConvertRule now stores type, scope, func, and an order integer, and PYCONVERT_RULES is now an ordered Pair{String,PyConvertRule}[] instead of a Dict of vectors.
  • Replaced the old signature pyconvert_add_rule(tname, T, func, priority) with pyconvert_add_rule(tname, T, S, func) which requires a scope S that must be a supertype of T, and added pyconvert_add_rule_high_priority for inserting higher-priority rules.
  • Adjusted rule lookup and filtering logic to consider scope and to try rules in insertion order (newer rules first) via the order field, and simplified the type/typename extraction and interface markers for arrays/buffers.
  • Updated all call sites to the new API across Convert, Wrap, JlWrap, NumpyDates/numpy.jl, ctypes.jl, and pandas.jl to pass explicit scopes and to register certain rules via new high-priority helpers; removed the old PyConvertPriority enum and related exports.
  • Added package initialization ordering in __init__ to register high-priority and canonical rules by calling JlWrap.init_base_rule_high_priority(), Wrap.init_wrap_rules_high_priority(), Convert.init_numpy_high_priority(), and Convert.init_pyconvert_canonical().
  • Added and updated tests in test/Convert.jl to assert new behavior: rule insertion ordering, correct conversion results, and an ArgumentError if a rule is registered with a type not a subtype of its scope.

Testing

  • Ran the updated test/Convert.jl unit tests which exercise added and modified conversion rules and ordering, and they passed.
  • Ran the package test suite via ] test for the changed modules to ensure initialization and conversion registrations succeed, and all tests passed.

Codex Task

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant