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

Inference for objects with C accelerators and pure-Python equivalents typically returns Uninferable #263

Open
pylint-bot opened this issue Nov 23, 2015 · 1 comment

Comments

@pylint-bot
Copy link
Owner

Originally reported by: BitBucket: ceridwenv, GitHub: ceridwenv


For instance, look at lazy_object_proxy.

>>> m = parse('import lazy_object_proxy; lazy_object_proxy.Proxy(lambda: None)')
>>> proxy_call = m.body[1].value
>>> proxy_call
<Call l.1 at 0x7fd5f48f4fd0>
>>> next(proxy_call.infer())
Uninferable

This happens because in lazy_object_proxy's __init__.py, the C accelerator is tried first. This is a typical pattern.

try:
    from .cext import Proxy
    from .cext import identity
except ImportError:
    from .slots import Proxy

Then, the module importing subsystem ends up building an empty module for lazy_object_proxy.cext.

(Pdb) self.astroid_cache['lazy_object_proxy.cext'].print_tree()
Module(
   name='lazy_object_proxy.cext',
   doc=None,
   package=False,
   pure_python=True,
   source_code=b'',
   source_file='<?>',
   body=[])

This happens even on PyPy and Jython, so the presence of any C accelerator will break inference for the pure Python equivalent.


@pylint-bot
Copy link
Owner Author

Original comment by Claudiu Popa (BitBucket: PCManticore, GitHub: PCManticore):


It might be worth to have a fallback on the pure Python import, if it is available. But since we don't know apriori which import is for a C extension, this could happen whenever a TryExcept is met with two imports on each branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant