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

Extract subtyping metaclass from FunsorMeta and domains #433

Closed
wants to merge 2 commits into from

Conversation

eb8680
Copy link
Member

@eb8680 eb8680 commented Jan 20, 2021

Addresses #351, #355.

This PR that attempts to isolate and reuse the parametric subtyping and type-caching functionality currently present in the metaclasses FunsorMeta, ArrayType and #430's ProductDomain, and to simplify their implementations. This change should enable nested Products and simplify the process of adding new Product/tuple-like Domains (i.e. with the same variance as Product).

More broadly, this PR represents a minimal first attempt to bring both interpreter types and funsor types closer to the Python typing type system, thereby saving us work, reducing cognitive overhead for users who are familiar with typing, and approaching compatibility with some of the wider tooling ecosystem built around typing. It may turn out that these potential advantages are outweighed by design choices in typing or multipledispatch, or that bugs, edge cases or performance limit the feasibility of this direction in practice, but it's hard to know without trying.

I will also put up a different version of these changes that integrates with typing more directly in a separate PR.

Tested:

  • Exercised by all existing tests

Copy link
Member

@fritzo fritzo left a comment

Choose a reason for hiding this comment

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

Seems like a good idea; I'm interested in hearing details tomorrow.

Comment on lines +245 to +251
if not hasattr(cls, "__args__"):
cls.__args__ = ()
if cls.__args__:
base, = bases
cls.__origin__ = base
else:
cls._type_cache = weakref.WeakValueDictionary()
Copy link
Member

Choose a reason for hiding this comment

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

could you add some comments here explaining when ._type_cache is used, etc.

@eb8680
Copy link
Member Author

eb8680 commented Feb 2, 2021

Closing as obsolete.

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.

2 participants