Skip to content

Comments

Support registration priority and use for Views#69

Merged
JacobHayes merged 2 commits intogoldenfrom
priority-registration
Jul 26, 2021
Merged

Support registration priority and use for Views#69
JacobHayes merged 2 commits intogoldenfrom
priority-registration

Conversation

@JacobHayes
Copy link
Member

Add support for priority-based registration (and erroring) to support the new View registration in #66.

I don't add get_priority to TypeSystem registration since the key there (class name / "key") isn't very meaningful. That might make more sense if we split TypeSystem._adapter_by_key to separate internal and system registries.

@JacobHayes JacobHayes self-assigned this Jul 26, 2021
@JacobHayes JacobHayes requested a review from mikss July 26, 2021 17:57
super().__init_subclass__(**kwargs)
if not cls.__abstract__:
register(cls._registry_, cls.python_type, cls)
register(cls._registry_, cls.python_type, cls, lambda x: x.priority)
Copy link
Member Author

Choose a reason for hiding this comment

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

I was gonna use attrgetter("priority") here, but mypy was a bit less strict - it could detect a misspelling like prioritiyz with a lambda, but not attrgetter. 🤷

Copy link
Contributor

@mikss mikss left a comment

Choose a reason for hiding this comment

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

Thanks, this is great.

I don't know where to put this in the code, so I'll record the thought here: .priority is dict-y for Views (b/c it's just type-to-view key-value lookup), but for-loop-y for TypeAdapters. This is probably fine, but just a quirk that .priority underlying usage is different for the two, despite similar naming of the two concepts.

@JacobHayes JacobHayes merged commit 35b4dc7 into golden Jul 26, 2021
@JacobHayes JacobHayes deleted the priority-registration branch July 26, 2021 18:26
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