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.

[BE] Add lazy_import

See original GitHub issue

🚀 Feature

Currently we used import in each DataPipe class to make lazy importing happens like https://github.com/pytorch/data/blob/4802a350d1bf954d0785e0f22fd1fcde2deded76/torchdata/datapipes/iter/load/iopath.py#L21-L29

As more potential libraries used in TorchData to support different functionalities, we could add a methods to support lazy import module to global namespace. Then, we don’t need to duplicate the import inside each class used the same third-party module.

Features needed:

  • Error message generation
  • Support from ... import ... as ...
  • Support submodule lazy import import xxx.yyy

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:1
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
eripcommented, Jan 4, 2022

So you want to stick with the current, but wrap up the try/except logic?

class XXXDataPipe:
    def __init__(self, ...):
        self._abc = lazy_import("abc")

    def __iter__(self):
        self._abc
1reaction
ejguancommented, Jan 4, 2022

In other words, attribute access on not-installed modules should never happen?

Yeah, you are right. The Error should be raised at the first place. Otherwise, it should be a bug.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Code-Splitting - React
The React.lazy function lets you render a dynamic import as a regular component. Before: import OtherComponent from './OtherComponent';. After:.
Read more >
Lazy Loading React Components (with react.lazy and suspense)
Head to the index.js file and import lazy and suspense from react like ... Below is the syntax for adding suspense component to...
Read more >
Lazy loading React components - LogRocket Blog
React.lazy() is a function that enables you to render a dynamic import as a regular component. Dynamic imports are a way of code-splitting, ......
Read more >
React Lazy Loading: The Best Complete Guide - CopyCat Blog
`React lazy()` makes it easy to render react components that are imported using the dynamic import() technique. The components are rendered as ...
Read more >
Lazy loading in React - LoginRadius Blog
We will perform lazy loading with React suspense and without it. First of all, create the app using npm create-react-app npm create-react-app my-app....
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