Skip to content

Refactor/alias kwargs#775

Merged
cvanelteren merged 6 commits into
Ultraplot:mainfrom
cvanelteren:refactor/alias-kwargs
Jul 18, 2026
Merged

Refactor/alias kwargs#775
cvanelteren merged 6 commits into
Ultraplot:mainfrom
cvanelteren:refactor/alias-kwargs

Conversation

@cvanelteren

@cvanelteren cvanelteren commented Jul 18, 2026

Copy link
Copy Markdown
Collaborator

Replacement of #774 which was dirty

This PR replaces the long inputs for aliases into a decorator to clean up some boilerplate code that exists.
Note that the functionality does not change, it just organizes it in a nicer manner to for both coders and users (I think).

…args

The internals package __init__ had grown into a grab-bag mixing keyword/alias
resolution with rc, location, and lazy-import helpers. Move the cohesive
keyword-argument cluster (_not_none, _alias_maps, the _pop_* poppers, and the
signature helpers) into a dedicated internals/kwargs.py, and re-export them from
the package so every existing 'from ..internals import _not_none' keeps working
unchanged. Add a new _alias_kwargs decorator that folds synonym keywords into
their canonical names with the same precedence and conflict warning as
_not_none, replacing the repetitive 'x = _not_none(x=x, y=y)' boilerplate at the
top of aliased functions.
Replace the six-line block of _not_none alias resolutions at the top of
Figure.__init__ with a single @_alias_kwargs table and drop the redundant alias
parameters (ref, aspect, axwidth, axheight, width, height) from the signature;
they are now folded into their canonical names before the body runs. Behavior is
unchanged, including the conflict warning and the refnum default of 1. This is
the first real adopter of the new decorator and the pattern for retiring the
scattered _not_none alias boilerplate elsewhere.
Adversarial review found that dropping the six _not_none lines let an explicit
Figure(refnum=None) survive as None instead of collapsing to 1 the way
_not_none(refnum=refnum, ref=ref, default=1) did, which loses the reference axes
and changes the figure size. Restore the canonical None default and coerce it
with a single _not_none call, and cover the case in the tests. Also reword the
decorator's conflict warning so it no longer implies the canonical keyword was
passed when two synonyms collide, and document that it handles keyword aliases
only.
The reusable style-parameter snippets (line, patch, pcolor/contour collections,
text) opened each numpydoc field with a pile of alias names like
'lw, linewidth, linewidths :', which every plotting method inherited and which
made the parameter tables hard to scan. Lead each field with the canonical name
and move the common documented synonyms into a short trailing 'Aliases:' note,
built through a small _aliases_note helper. This also fixes a drifted typo in the
contour snippet ('a, alpha, alpha' -> 'a, alpha, alphas'). Behavior is unchanged;
all synonyms are still accepted at runtime via _pop_props.
The geo format docstring documented gridline-locator aliases as separate
'lonlines, latlines : optional / Aliases for lonlocator, latlocator' blocks
sitting next to the canonical entries, doubling the number of parameter entries
a reader scans. Fold each alias set into a trailing 'Aliases:' note on its
canonical entry (lonlocator, lonlocator_kw, lonminorlocator, lonminorlocator_kw),
matching the shared style-snippet presentation. Documentation only; the alias
keywords are still accepted.
@codecov

codecov Bot commented Jul 18, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.56118% with 20 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
ultraplot/internals/kwargs.py 84.37% 13 Missing and 7 partials ⚠️

📢 Thoughts on this report? Let us know!

@cvanelteren
cvanelteren marked this pull request as ready for review July 18, 2026 09:54
@cvanelteren
cvanelteren merged commit 1be6eea into Ultraplot:main Jul 18, 2026
18 checks passed
@cvanelteren
cvanelteren deleted the refactor/alias-kwargs branch July 18, 2026 09:57
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.

1 participant