lazy imports

I'm a contributor to the Bazaar project and their project uses a lazy import mechanism to help speed up start times. Unfortunately, PyCharm doesn't recognize these lazy imports and marks all the code which uses the lazily imported modules with errors. I was wondering if there was anything that could be done about this?

The lazy imports look like this:

from bzrlib.lazy_import import lazy_import

lazy_import(globals(), """

import codecs

import errno

import threading

from warnings import warn

import bzrlib

from bzrlib import (

    cleanup,

    cmdline,

    debug,

    errors,

    option,

    osutils,

    trace,

    ui,

    win32utils,

    )

""")

3 comments

Hello Gordon,

I don't think there's any way for PyCharm to handle this. Later we may provide

an extensibility point that would allow you to write a custom plugin allowing

PyCharm to understand such style, but at the moment there is no such extensibility.

I'm a contributor to the Bazaar project and their project uses a lazy

import mechanism to help speed up start times. Unfortunately, PyCharm

doesn't recognize these lazy imports and marks all the code which uses

the lazily imported modules with errors. I was wondering if there was

anything that could be done about this?

The lazy imports look like this:

from bzrlib.lazy_import import lazy_import

lazy_import(globals(), """

import codecs

import errno

import threading

from warnings import warn

import bzrlib

from bzrlib import (

cleanup,

cmdline,

debug,

errors,

option,

osutils,

trace,

ui,

win32utils,

)

""")

--

Dmitry Jemerov

Development Lead

JetBrains, Inc.

http://www.jetbrains.com/

"Develop with Pleasure!"

0

Allowing for a plugin to deal with the lazy import mechanism would be great !

Luis

0

Please sign in to leave a comment.