Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove dead _get_channels_mapping code #3467

Merged
merged 5 commits into from
Jul 13, 2024

Conversation

dangotbanned
Copy link
Member

@dangotbanned dangotbanned commented Jul 10, 2024

"_get_channels_mapping" is not accessed Pylance

I've been seeing this message for a while and thought I'd investigate.

This function appears in the first v5 commit to api

def _get_channels_mapping():
mapping = {}
for attr in dir(channels):
cls = getattr(channels, attr)
if isinstance(cls, type) and issubclass(cls, core.SchemaBase):
mapping[cls] = attr.replace("Value", "").lower()
return mapping

It was not referenced back then (2021), and still is not referenced.

It looks like an early version of the channels module manipulation code replaced in #3444

As this is a private function, I don't feel there's a strong case for keeping it around.
It also doesn't behave the same as the old infer_encoding_types - so any hypothetical usage wouldn't produce the same spec:

channel_objs = (getattr(channels, name) for name in dir(channels))
        if channels
    channel_objs = (
        else _ChannelCache.from_cache()
        c for c in channel_objs if isinstance(c, type) and issubclass(c, SchemaBase)
    )
    )
    channel_to_name: dict[type[SchemaBase], str] = {
        c: c._encoding_name for c in channel_objs
    }
    name_to_channel: dict[str, dict[str, type[SchemaBase]]] = {}
    for chan, name in channel_to_name.items():
        chans = name_to_channel.setdefault(name, {})
        if chan.__name__.endswith("Datum"):
            key = "datum"
        elif chan.__name__.endswith("Value"):
            key = "value"
        else:
            key = "field"
        chans[key] = chan

Copy link
Contributor

@joelostblom joelostblom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but I'll leave it open in case someone else wants to confirm

@dangotbanned
Copy link
Member Author

Think there was a false positive in https://github.com/vega/altair/actions/runs/9905108163/job/27363929771?pr=3467

Can't repro locally

>>> hatch test
cmd [1] | ruff check .
All checks passed!
cmd [2] | ruff format --diff --check .
84 files already formatted 
cmd [3] | mypy altair tests
Success: no issues found in 367 source files
cmd [4] | pytest -p no:randomly -n logical --numprocesses=logical --doctest-modules tests altair
==================================== 1257 passed, 1 skipped, 1 xfailed, 2 xpassed in 52.68s ====================================

@dangotbanned
Copy link
Member Author

Think there was a false positive in vega/altair/actions/runs/9905108163/job/27363929771?pr=3467

Can't repro locally

>>> hatch test
cmd [1] | ruff check .
All checks passed!
cmd [2] | ruff format --diff --check .
84 files already formatted 
cmd [3] | mypy altair tests
Success: no issues found in 367 source files
cmd [4] | pytest -p no:randomly -n logical --numprocesses=logical --doctest-modules tests altair
==================================== 1257 passed, 1 skipped, 1 xfailed, 2 xpassed in 52.68s ====================================

I see this is failing again in https://github.com/vega/altair/actions/runs/9905108163/job/27364311474?pr=3467

@mattijn should I fix this in a new PR or in this one?

It isn't related to the changes I've made here at all

@mattijn
Copy link
Contributor

mattijn commented Jul 12, 2024

Do we know where this error was introduced? I can't remember merging a PR with errors in CI.

@dangotbanned
Copy link
Member Author

dangotbanned commented Jul 12, 2024

Do we know where this error was introduced? I can't remember merging a PR with errors in CI.

@mattijn

I've got a fix for it I'm about to push on a new PR #3475

It looks to be a change over at jsonschema, but I think it is unlikely to be python-jsonschema/jsonschema@0024b58#diff-0187567512f508c6badb2b034443e72b00316d8c0f40d5d7078eb5cb9adaf9f4

dangotbanned added a commit to dangotbanned/altair that referenced this pull request Jul 12, 2024
binste pushed a commit that referenced this pull request Jul 13, 2024
…3475)

* fix(typing): Confirm arg type before joining in `_deduplicate_enum_errors`

Fixes `mypy` error that appeared during a merge #3467 (comment)

* revert: undo last commit

* revert: Ignore type error introduced by `typeshed`

The issue is not related to any runtime changes python-jsonschema/jsonschema#1019 (comment)
@mattijn mattijn merged commit bed0965 into vega:main Jul 13, 2024
11 checks passed
@dangotbanned dangotbanned deleted the remove-get-channels-mapping branch July 13, 2024 17:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants