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

Invalid automatic type import #1025

Open
IvarVirusiim opened this issue Jun 8, 2023 · 1 comment
Open

Invalid automatic type import #1025

IvarVirusiim opened this issue Jun 8, 2023 · 1 comment
Assignees
Labels

Comments

@IvarVirusiim
Copy link

Describe the bug

When trying to import using PyCharm, using for example VirtualMachine, it imports pyVmomi.vim.VirtualMachine, but the correct import is vim.VirtualMachine. This causes errors during runtime.

Reproduction steps

  1. Try to import some type automatically
    image

  2. Run the code and get error: ImportError: cannot import name 'VirtualMachine' from 'pyVmomi.vim' (unknown location)

Expected behavior

Import would be correct: from vim import VirtualMachine

Additional context

No response

@DanielDraganov DanielDraganov self-assigned this Jun 21, 2023
@mk-fg
Copy link

mk-fg commented Aug 3, 2023

I have similar issue with this code:

import pyVmomi.vim as vim
print(vim.Task)
# Result (unexpected): AttributeError: module 'pyVmomi.vim' has no attribute 'Task'

While this equivalent-at-a-glance code works:

from pyVmomi import vim
print(vim.Task)
# Result (expected): <class 'pyVmomi.VmomiSupport.vim.Task'>

Furthermore, if e.g. import pyVmomi.vim is called first, it breaks the module within that python runtime, for example:

import pyVmomi.vim

from pyVmomi import vim
print(vim.Task)
# Result (unexpected): AttributeError: module 'pyVmomi.vim' has no attribute 'Task'

If this is not easy to fix, I'd recommend adding something like raise ImportError('Use "from pyVmomi import vim" ...') when module is imported via import X, which should be detectable via same missing class-attribute lookups.

This way, at least it'd be clear what the issue is, as otherwise it looks like module and all example code for it is outdated or broken in current pip releases, as it tries to use no-longer-existant module attributes.

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

No branches or pull requests

3 participants