question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Type checking + autocomplete don't work with the Linen API

See original GitHub issue

Modules in Linen are defined similar to dataclasses yet they aren’t dataclasses as such so the type checkers and the IDEs have no way on knowing what arguments each Module expects. This yields a lot of type checking errors and makes it harder to get automatic documentation.

Since the API is new maybe this could be taken into consideration early to avoid changes in the future.

Also, how does one perform logic similar to the one you would do in __init__ in this API? I know about setup but sometimes you e.g. accept union types in the constructor and transform them to a standardize type for a field.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:6
  • Comments:16 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
thomkehcommented, Jun 23, 2021

The pyright team has a proposal for how to specify “dataclass-like semantics” for custom classes, which would solve the problem in this issue. They intend to submit this as a PEP, but they have also already implemented this spec in pyright and pylance, so VS Code users can directly make use of it. pydantic has a PR for supporting this spec.

Would the flax team be open to supporting this? As far as I can tell, it just involves creating a decorator called __dataclass_transform__ (that doesn’t do anything at runtime) and applying it to the base class.

1reaction
NeilGirdharcommented, Jan 19, 2022

FYI: The dataclass transform PEP is now in draft.

I mentioned Flax’s dataclass during the discussion, and they agreed to support applying the decorator to classes directly (instead of just to metaclasses), and pyright has already implemented that suggestion.

Read more comments on GitHub >

github_iconTop Results From Across the Web

typeahead.js autocomplete is not showing any suggestions ...
I can see that while typing the name in customer textbox there is a call to my API but nothing is getting displayed...
Read more >
How to Make an Auto Complete Search Input in React.js
In this video, I've shown you how can you make your own auto-complete search address input in react using an npm library ...
Read more >
New, "Improved" Places SDK. PlacePicker deprecated! No ...
I just got an email detailing changes to the Places SDK. Of interest to me is that the PlacePicker is now deprecated, and...
Read more >
HTML attribute: disabled - HTML: HyperText Markup Language
The Boolean disabled attribute, when present, makes the element not mutable, focusable, or even submitted with the form.
Read more >
Type checking and auto-completion in Plunker - AG Grid Blog
No more will you be left scratching your head wondering why a demo is not working due to a typo! Catch Type Errors....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found