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

Prevent module creation pyright type errors #702

Merged
merged 1 commit into from
Aug 2, 2023

Conversation

NeilGirdhar
Copy link
Contributor

@NeilGirdhar NeilGirdhar commented Jul 22, 2023

Creating any Haiku module gives type errors on the latest Pyright due to the module metaclass specification (microsoft/pyright#5561). The issue is that the ideal type annotation is an intersection of type[T] and ModuleMetaclass where T is the return type, but Python doesn't have type intersections yet. The authors of the code chose type[T], but Pyright requires ModuleMetaclass.

@NeilGirdhar
Copy link
Contributor Author

NeilGirdhar commented Jul 22, 2023

Incidentally, I think most if not all of what is done in the metaclass should be moved into Module.__init_subclass__. Metaclasses have significant compatibility issues (you can't inherit from two classes with different metaclasses). It's best to avoid them.

@NeilGirdhar NeilGirdhar force-pushed the fix_pyright branch 3 times, most recently from 32928f7 to f0b8ec2 Compare July 24, 2023 16:03
@superbobry
Copy link
Collaborator

Thanks, Neil!

haiku/_src/module.py Outdated Show resolved Hide resolved
Creating any Haiku module gives type errors on the latest Pyright due to
the module metaclass specification
(microsoft/pyright#5561).  The issue is
that the ideal type annotation is an intersection of `type[T]` and
`ModuleMetaclass` where `T` is the return type, but Python doesn't have
type intersections yet.  The authors of the code chose `type[T]`, but
Pyright requires `ModuleMetaclass`.
@copybara-service copybara-service bot merged commit b7b150f into google-deepmind:main Aug 2, 2023
6 checks passed
@NeilGirdhar NeilGirdhar deleted the fix_pyright branch August 2, 2023 14:35
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