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

Replace "Either" trait type with "Union" #405

Merged
merged 1 commit into from
Apr 21, 2021

Conversation

rahulporuri
Copy link
Contributor

This PR replaces the Either trait with the Union trait.

A new Union trait type has been added. This is intended as a simpler replacement for the existing Either trait type, which will eventually be deprecated.

See https://github.com/enthought/traits/releases/tag/6.1.0.

See similar PR in traitsui enthought/traitsui#1581

	modified:   envisage/service_offer.py
Copy link
Contributor

@aaronayres35 aaronayres35 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 same comments as from my review on enthought/traitsui#1581

I believe these traits used to default to None but now they default to "". This possibly is no problem at all, but we should be aware of the change.

@mdickinson
Copy link
Member

mdickinson commented Apr 21, 2021

I think we can reasonably assume that the protocol and factory traits are always provided when creating a ServiceOffer, so that we don't have to worry too much about default values.

To back that up, here's where the protocol is used, and where we dispatch based on whether it's a string or not; it's clear that if the default value of None reached that code, it would do the wrong thing:

if isinstance(protocol_or_name, str):
name = protocol_or_name
else:
name = "%s.%s" % (
protocol_or_name.__module__,
protocol_or_name.__name__,
)

And for the factory, here's where the string versus callable is resolved:

if isinstance(obj, str):
obj = ImportManager().import_symbol(obj)
obj = obj(**properties)

IOW, LGTM.

@rahulporuri rahulporuri merged commit 182ecd9 into master Apr 21, 2021
@rahulporuri rahulporuri deleted the ref/replace-either-trait-with-union branch April 21, 2021 10:31
@rahulporuri
Copy link
Contributor Author

thanks for the review @mdickinson and @aaronayres35

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.

3 participants