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

Missing imports in VS Code #175

Closed
felixhammerl opened this issue Jun 21, 2021 · 1 comment · Fixed by #190
Closed

Missing imports in VS Code #175

felixhammerl opened this issue Jun 21, 2021 · 1 comment · Fixed by #190

Comments

@felixhammerl
Copy link

Hi folks,

I am not sure if this is an issue that this codebase should concern itself with, but here's something strange that I have noticed when using VS Code and Pylance.

When using the from hamcrest import * preamble in my tests, VS Code spits out the following error:

Screenshot 2021-06-21 at 19 06 20

It seems that for whichever reason, Pylance fails to resolve won't resolve nested wildcard imports. When explicitly importing, the submodules, it works as expected.

from hamcrest import *
from hamcrest.core import assert_that
@felixhammerl
Copy link
Author

Digging into it, I think that it's this behavior that causes Pylance to trip up: https://docs.python.org/3/tutorial/modules.html#importing-from-a-package

Now what happens when the user writes from sound.effects import *? Ideally, one would hope that this somehow goes out to the filesystem, finds which submodules are present in the package, and imports them all. This could take a long time and importing sub-modules might have unwanted side-effects that should only happen when the sub-module is explicitly imported.

The only solution is for the package author to provide an explicit index of the package. The import statement uses the following convention: if a package’s init.py code defines a list named all, it is taken to be the list of module names that should be imported when from package import * is encountered. It is up to the package author to keep this list up-to-date when a new version of the package is released. Package authors may also decide not to support it, if they don’t see a use for importing * from their package. For example, the file sound/effects/init.py could contain the following code:

If all is not defined, the statement from sound.effects import * does not import all submodules from the package sound.effects into the current namespace; it only ensures that the package sound.effects has been imported (possibly running any initialization code in init.py) and then imports whatever names are defined in the package.

It seems that the Python runtime can deal with this, as my tests pass, but we should use __all__ to make give an indication of what all should be loaded.

felixhammerl added a commit to felixhammerl/PyHamcrest that referenced this issue Jun 21, 2021
Missing __all__ causes Pylance claim that assert_that has not been imported for wildcard imports.

Fixes hamcrest#175
felixhammerl added a commit to felixhammerl/PyHamcrest that referenced this issue Jun 21, 2021
Missing __all__ causes Pylance claim that assert_that has not been imported for wildcard imports.

Fixes hamcrest#175
offbyone pushed a commit that referenced this issue Dec 12, 2021
kraj pushed a commit to YoeDistro/meta-openembedded that referenced this issue Jan 4, 2022
Changelog:
=========
  Features
-------------
 - * Adds the tests to the sdist. Fixed by openembedded#150

 openembedded#141 <hamcrest/PyHamcrest#141>
 - * Update the CI to test Python 3.10

 openembedded#160 <hamcrest/PyHamcrest#160>
 - * Add pretty string representation for matchers objects

 openembedded#170 <hamcrest/PyHamcrest#170>

 Bugfixes
------------
 - * Test coverage is now submitted to codecov.io.

 Fixed by openembedded#150

 openembedded#135 <hamcrest/PyHamcrest#135>
 - Change to the ``has_entry()`` matcher - if exactly one key matches,
   but the value does not, report only the mismatching value.

 Fixed by openembedded#157

 openembedded#156 <hamcrest/PyHamcrest#156>
 - * Fix is_() type annotations

 openembedded#180 <hamcrest/PyHamcrest#180>

 Misc
-------------
 - openembedded#150 <hamcrest/PyHamcrest#150>
   openembedded#159 <hamcrest/PyHamcrest#159>
   openembedded#162 <hamcrest/PyHamcrest#162>
   openembedded#163 <hamcrest/PyHamcrest#163>
   openembedded#166 <hamcrest/PyHamcrest#166>
   openembedded#175 <hamcrest/PyHamcrest#175>

Signed-off-by: Wang Mingyu <[email protected]>
Signed-off-by: Khem Raj <[email protected]>
kraj pushed a commit to YoeDistro/meta-openembedded that referenced this issue Jan 4, 2022
Changelog:
=========
  Features
-------------
 - * Adds the tests to the sdist. Fixed by openembedded#150

 openembedded#141 <hamcrest/PyHamcrest#141>
 - * Update the CI to test Python 3.10

 openembedded#160 <hamcrest/PyHamcrest#160>
 - * Add pretty string representation for matchers objects

 openembedded#170 <hamcrest/PyHamcrest#170>

 Bugfixes
------------
 - * Test coverage is now submitted to codecov.io.

 Fixed by openembedded#150

 openembedded#135 <hamcrest/PyHamcrest#135>
 - Change to the ``has_entry()`` matcher - if exactly one key matches,
   but the value does not, report only the mismatching value.

 Fixed by openembedded#157

 openembedded#156 <hamcrest/PyHamcrest#156>
 - * Fix is_() type annotations

 openembedded#180 <hamcrest/PyHamcrest#180>

 Misc
-------------
 - openembedded#150 <hamcrest/PyHamcrest#150>
   openembedded#159 <hamcrest/PyHamcrest#159>
   openembedded#162 <hamcrest/PyHamcrest#162>
   openembedded#163 <hamcrest/PyHamcrest#163>
   openembedded#166 <hamcrest/PyHamcrest#166>
   openembedded#175 <hamcrest/PyHamcrest#175>

Signed-off-by: Wang Mingyu <[email protected]>
Signed-off-by: Khem Raj <[email protected]>
kraj pushed a commit to YoeDistro/meta-openembedded that referenced this issue Jan 4, 2022
Changelog:
=========
  Features
-------------
 - * Adds the tests to the sdist. Fixed by openembedded#150

 openembedded#141 <hamcrest/PyHamcrest#141>
 - * Update the CI to test Python 3.10

 openembedded#160 <hamcrest/PyHamcrest#160>
 - * Add pretty string representation for matchers objects

 openembedded#170 <hamcrest/PyHamcrest#170>

 Bugfixes
------------
 - * Test coverage is now submitted to codecov.io.

 Fixed by openembedded#150

 openembedded#135 <hamcrest/PyHamcrest#135>
 - Change to the ``has_entry()`` matcher - if exactly one key matches,
   but the value does not, report only the mismatching value.

 Fixed by openembedded#157

 openembedded#156 <hamcrest/PyHamcrest#156>
 - * Fix is_() type annotations

 openembedded#180 <hamcrest/PyHamcrest#180>

 Misc
-------------
 - openembedded#150 <hamcrest/PyHamcrest#150>
   openembedded#159 <hamcrest/PyHamcrest#159>
   openembedded#162 <hamcrest/PyHamcrest#162>
   openembedded#163 <hamcrest/PyHamcrest#163>
   openembedded#166 <hamcrest/PyHamcrest#166>
   openembedded#175 <hamcrest/PyHamcrest#175>

Signed-off-by: Wang Mingyu <[email protected]>
Signed-off-by: Khem Raj <[email protected]>
halstead pushed a commit to openembedded/meta-openembedded that referenced this issue Jan 5, 2022
Changelog:
=========
  Features
-------------
 - * Adds the tests to the sdist. Fixed by #150

 #141 <hamcrest/PyHamcrest#141>
 - * Update the CI to test Python 3.10

 #160 <hamcrest/PyHamcrest#160>
 - * Add pretty string representation for matchers objects

 #170 <hamcrest/PyHamcrest#170>

 Bugfixes
------------
 - * Test coverage is now submitted to codecov.io.

 Fixed by #150

 #135 <hamcrest/PyHamcrest#135>
 - Change to the ``has_entry()`` matcher - if exactly one key matches,
   but the value does not, report only the mismatching value.

 Fixed by #157

 #156 <hamcrest/PyHamcrest#156>
 - * Fix is_() type annotations

 #180 <hamcrest/PyHamcrest#180>

 Misc
-------------
 - #150 <hamcrest/PyHamcrest#150>
   #159 <hamcrest/PyHamcrest#159>
   #162 <hamcrest/PyHamcrest#162>
   #163 <hamcrest/PyHamcrest#163>
   #166 <hamcrest/PyHamcrest#166>
   #175 <hamcrest/PyHamcrest#175>

Signed-off-by: Wang Mingyu <[email protected]>
Signed-off-by: Khem Raj <[email protected]>
Signed-off-by: Trevor Gamblin <[email protected]>
daregit pushed a commit to daregit/yocto-combined that referenced this issue May 22, 2024
Changelog:
=========
  Features
-------------
 - * Adds the tests to the sdist. Fixed by #150

 #141 <hamcrest/PyHamcrest#141>
 - * Update the CI to test Python 3.10

 #160 <hamcrest/PyHamcrest#160>
 - * Add pretty string representation for matchers objects

 #170 <hamcrest/PyHamcrest#170>

 Bugfixes
------------
 - * Test coverage is now submitted to codecov.io.

 Fixed by #150

 #135 <hamcrest/PyHamcrest#135>
 - Change to the ``has_entry()`` matcher - if exactly one key matches,
   but the value does not, report only the mismatching value.

 Fixed by #157

 #156 <hamcrest/PyHamcrest#156>
 - * Fix is_() type annotations

 #180 <hamcrest/PyHamcrest#180>

 Misc
-------------
 - #150 <hamcrest/PyHamcrest#150>
   #159 <hamcrest/PyHamcrest#159>
   #162 <hamcrest/PyHamcrest#162>
   #163 <hamcrest/PyHamcrest#163>
   #166 <hamcrest/PyHamcrest#166>
   #175 <hamcrest/PyHamcrest#175>

Signed-off-by: Wang Mingyu <[email protected]>
Signed-off-by: Khem Raj <[email protected]>
Signed-off-by: Trevor Gamblin <[email protected]>
daregit pushed a commit to daregit/yocto-combined that referenced this issue May 22, 2024
Changelog:
=========
  Features
-------------
 - * Adds the tests to the sdist. Fixed by #150

 #141 <hamcrest/PyHamcrest#141>
 - * Update the CI to test Python 3.10

 #160 <hamcrest/PyHamcrest#160>
 - * Add pretty string representation for matchers objects

 #170 <hamcrest/PyHamcrest#170>

 Bugfixes
------------
 - * Test coverage is now submitted to codecov.io.

 Fixed by #150

 #135 <hamcrest/PyHamcrest#135>
 - Change to the ``has_entry()`` matcher - if exactly one key matches,
   but the value does not, report only the mismatching value.

 Fixed by #157

 #156 <hamcrest/PyHamcrest#156>
 - * Fix is_() type annotations

 #180 <hamcrest/PyHamcrest#180>

 Misc
-------------
 - #150 <hamcrest/PyHamcrest#150>
   #159 <hamcrest/PyHamcrest#159>
   #162 <hamcrest/PyHamcrest#162>
   #163 <hamcrest/PyHamcrest#163>
   #166 <hamcrest/PyHamcrest#166>
   #175 <hamcrest/PyHamcrest#175>

Signed-off-by: Wang Mingyu <[email protected]>
Signed-off-by: Khem Raj <[email protected]>
Signed-off-by: Trevor Gamblin <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant