Closed vsfeedback closed 11 months ago
Seems like a duplicate of #7068 and #6713
More from the original post:
I worked on this a bit further. It turns out to be a circular import problem (see below). The possible bug is that I never got an importError or any other exception. Instead, I got a runtime exception (NameError: name ‘IDLmAJAX’ is not defined). This problem can be easily (not really) reproduced be creating 3 (yes 3) files. IDLmBuild.py
from IDLmAJAX import from IDLmUtility import IDLmUtility.getPerceptualHash(‘a’)
IDLmUtility.py
from IDLmAJAX import * class IDLmUtility(object): @staticmethod def getPerceptualHash(urlStr): print(IDLmAJAX) IDLmAJAX.py
from IDLmUtility import * class IDLmAJAX(object): def runAJAX(): pass
Note that IDLmBuild.py is the ‘main’ program where execution should start. See below.
C:\Users\Peter\Documents\Visual Studio 2022\projects\PythonApps\PythonApps>py IDLmBuild.py
Traceback (most recent call last):
File “C:\Users\Peter\Documents\Visual Studio 2022\projects\PythonApps\PythonApps\IDLmBuild.py”, line 3, in
Hi there, could you change from IDLmAJAX import *
to import IDLmAJAX
? That should solve your issue. I believe the former one only creates references to all things defined in module IDLmAJAX, but the module itself is not defined, so it won't work. Please re-open the ticket if the issue persists. Thanks.
Hi StellaHuang95,
I made the changes you suggested (and some more) and the problem still exists. The current files are provided below.
IDLmAJAX.py
import IDLmUtility class IDLmAJAX(object): def runAJAX(): pass
IDLmBuild.py
import IDLmAJAX
import IDLmUtility
IDLmUtility.g()
IDLmUtility.py
import IDLmAJAX
class IDLmUtility(object):
@staticmethod
def g():
print(IDLmAJAX)
When I run IDLmBuild I get "module 'IDLmUtility' has no attribute 'g'"
Of course, that is not true. Worse, Python never detects/reports the circular imports.
Thank you
Peter Schaeffer
Hi @pschaeffer, the diagnostics for cyclical import chains is set to "none" by default to not slow down type analysis. You can go to Tools -> Options -> Python -> Analysis and change the Type checking mode to strict and reload the project to see the errors.
Hi,
I tried the suggested change. It made no difference. I did not know how to reload the project, so I shutdown VS 2022 completely and restarted it (first I switched to strict mode).
Thank you
Peter Schaeffer
Hi,
I tried the suggested change. It made no difference. I did not know how to reload the project, so I shutdown VS 2022 completely and restarted it (first I switched to strict mode).
Thank you
Peter Schaeffer
From: Stella @.> Sent: Monday, February 27, 2023 3:46 PM To: microsoft/PTVS @.> Cc: Peter Schaeffer @.>; Mention @.> Subject: Re: [microsoft/PTVS] reportMissingModuleSource: Visual Studio 2022 / Python (Issue #7393)
Hi @pschaeffer https://github.com/pschaeffer , the diagnostics for cyclical import chains is set to "none" by default to not slow down type analysis. You can go to Tools -> Options -> Python -> Analysis and change the Type checking mode to strict and reload the project to see the errors.
— Reply to this email directly, view it on GitHub https://github.com/microsoft/PTVS/issues/7393#issuecomment-1447146552 , or unsubscribe https://github.com/notifications/unsubscribe-auth/AA4LSSXHOCXNWTBACRNKPADWZUOBJANCNFSM6AAAAAAUW3X7QU . You are receiving this because you were mentioned. https://github.com/notifications/beacon/AA4LSSTM6TIHGVAZUA3AZS3WZUOBJA5CNFSM6AAAAAAUW3X7QWWGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTSWIG2DQ.gif Message ID: @. @.> >
Great, glad that the issue has been resolved. And yes, reloading just means restart VS or close the project and open again.
Hi,
I tried you suggested change. It did not resolve the problem. Indeed, it made no difference that I could tell.
Thank you
Peter Schaeffer
@pschaeffer Could you share the screenshot? So you're saying that after you changed to strict mode, the circular import error didn't show in the error list? What's your diagnostic mode? Thanks!
Hi Stella,
I carefully looked in the error list and found
Severity
Code
Description
Project
File
Line
Suppression State
Error (active)
Cycle detected in import chain c:\Users\Peter\Documents\Visual Studio 2022\Projects\PythonApps\PythonApps\IDLmAJAX.py c:\Users\Peter\Documents\Visual Studio 2022\Projects\PythonApps\PythonApps\IDLmUtility.py
C:\Users\Peter\Documents\Visual Studio 2022\Projects\PythonApps\PythonApps\IDLmAJAX.py
1
What is strange is that sometimes I see the ‘Cycle detected’ error message and sometimes I don’t.
Right now, I don’t have the error message.
Thank you
Peter Schaeffer
From: Stella @.> Sent: Tuesday, February 28, 2023 12:50 PM To: microsoft/PTVS @.> Cc: Peter Schaeffer @.>; Mention @.> Subject: Re: [microsoft/PTVS] reportMissingModuleSource: Visual Studio 2022 / Python (Issue #7393)
@pschaeffer https://github.com/pschaeffer Could you share the screenshot? So you're saying that after you changed to strict mode, the circular import error didn't show in the error list? Thanks!
— Reply to this email directly, view it on GitHub https://github.com/microsoft/PTVS/issues/7393#issuecomment-1448690648 , or unsubscribe https://github.com/notifications/unsubscribe-auth/AA4LSSXTJFHLMM6RBUCNLYTWZZCGDANCNFSM6AAAAAAUW3X7QU . You are receiving this because you were mentioned. https://github.com/notifications/beacon/AA4LSSVLKSLUZZXFCRCB6L3WZZCGDA5CNFSM6AAAAAAUW3X7QWWGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTSWLFB5Q.gif Message ID: @. @.> >
Hi,
Let me offer another comment. I would think Python would report a circular import error in all cases (at runtime). However, this does not appear to be true.
I wasn't able to repro this on my end, but I suspect that it may be related to the time it takes for Pylance to start the service instance and finish the diagnosis. In some cases, if the service instance isn't fully started, it may not be able to detect the cycle and the error won't appear . Could you be more specific on when you didn't see the ‘Cycle detected’ error message? Was this after loading the solution?
I ran another test just a few minutes ago. Definitely still a problem. Should I send you the 'IDLM*' files so that you can reproduce the problem? My test environment is Visual Studio 2022 (PTVS). I also reproduced the same exact problem from the command line entirely outside of VS 2022. I can provide screen shots if that will help.
Thanks, I would be happy to take a look at the files and screenshots you have, but based on what you've described, it sounds like the issue may not be related to PTVS or Visual Studio. Since you mentioned that you were able to reproduce the problem outside of VS as well, it may be outside of our scope to fix. Nonetheless, I'd be glad to take a look and see if I can offer any suggestions or guidance. Please feel free to send over the files and screenshots.
Hi,
Here are the files and screen shots I promised.
Thank you
Peter Schaeffer
From: Stella @.> Sent: Thursday, April 20, 2023 12:23 PM To: microsoft/PTVS @.> Cc: Peter Schaeffer @.>; Mention @.> Subject: Re: [microsoft/PTVS] reportMissingModuleSource: Visual Studio 2022 / Python (Issue #7393)
Thanks, I would be happy to take a look at the files and screenshots you have, but based on what you've described, it sounds like the issue may not be related to PTVS or Visual Studio. Since you mentioned that you were able to reproduce the problem outside of VS as well, it may be outside of our scope to fix. Nonetheless, I'd be glad to take a look and see if I can offer any suggestions or guidance. Please feel free to send over the files and screenshots.
— Reply to this email directly, view it on GitHub https://github.com/microsoft/PTVS/issues/7393#issuecomment-1516689226 , or unsubscribe https://github.com/notifications/unsubscribe-auth/AA4LSSQWH5HR5CV4CAS7YW3XCFWHZANCNFSM6AAAAAAUW3X7QU . You are receiving this because you were mentioned. https://github.com/notifications/beacon/AA4LSSS2KGEXK764K2DNRM3XCFWHZA5CNFSM6AAAAAAUW3X7QWWGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTS2M3LUU.gif Message ID: @. @.> >
I don't see the files. Could you try again and comment under this issue directly?
Hello,
Here are the files. I put gif at the end of the py files because this system does not like py files. You will have to rename 3 files. All of the files to be renamed start with IDLM.
Thank you
Peter Schaeffer
Could you try zip it up and send the .zip file?
Hi Stella,
How about this zipx file?
Thank you
Peter Schaeffer
From: Stella @.> Sent: Monday, April 24, 2023 1:23 PM To: microsoft/PTVS @.> Cc: Peter Schaeffer @.>; Mention @.> Subject: Re: [microsoft/PTVS] reportMissingModuleSource: Visual Studio 2022 / Python (Issue #7393)
Could you try zip it up and send the .zip file?
— Reply to this email directly, view it on GitHub https://github.com/microsoft/PTVS/issues/7393#issuecomment-1520631066 , or unsubscribe https://github.com/notifications/unsubscribe-auth/AA4LSSQQCDQ7XA7R6N27DH3XC3AJDANCNFSM6AAAAAAUW3X7QU . You are receiving this because you were mentioned. https://github.com/notifications/beacon/AA4LSST6FVKL5IMAGUQZ3ILXC3AJDA5CNFSM6AAAAAAUW3X7QWWGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTS2UL6RU.gif Message ID: @. @.> >
Hello Stella,
The actual file is a zipx file. However, I renamed it to be a jpeg file to get around upload restrictions.
Thank you
Peter Schaeffer
I still couldn't access the files, were you able to upload .zip files? The supported file type seems include .zip.
Thanks, now I see the code. The issue is that you are trying to call the g()
method directly from the module using IDLmUtility.g()
, but g()
is a static method in the IDLmUtility
class. You can either change that to IDLmUtility.IDLmUtility.g()
or change the import statement to from IDLmUtility import IDLmUtility
to fix the error.
Hello,
Thank you for the update. Shouldn’t I get some kind of import error with this structure?
Thank you
Peter Schaeffer
From: Stella @.> Sent: Wednesday, April 26, 2023 7:09 PM To: microsoft/PTVS @.> Cc: Peter Schaeffer @.>; Mention @.> Subject: Re: [microsoft/PTVS] reportMissingModuleSource: Visual Studio 2022 / Python (Issue #7393)
Thanks, now I see the code. The issue is that you are trying to call the g() method directly from the module using IDLmUtility.g(), but g() is a static method in the IDLmUtility class. You can either change that to IDLmUtility.IDLmUtility.g() or change the import statement to from IDLmUtility import IDLmUtility to fix the error.
— Reply to this email directly, view it on GitHub https://github.com/microsoft/PTVS/issues/7393#issuecomment-1524253825 , or unsubscribe https://github.com/notifications/unsubscribe-auth/AA4LSSRXL556GL34MVP4TZDXDG2K5ANCNFSM6AAAAAAUW3X7QU . You are receiving this because you were mentioned. https://github.com/notifications/beacon/AA4LSSWMXYUZ4RWVAYPY4IDXDG2K5A5CNFSM6AAAAAAUW3X7QWWGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTS23JCIC.gif Message ID: @. @.> >
Hello,
Thank you for the update. Shouldn’t I get some kind of import error with this structure?
Thank you
Peter Schaeffer
Hi there, we wish we were able to thoroughly investigate all issues and leave all feature requests open indefinitely, but unfortunately, we have limited resources and it’s hard to organize and prioritize our work if we have a large number of issues open in our repository. If you find that this issue persists and falls within the scope of PTVS, could you please reopen it with the following details:
Detailed reproduction steps with expected and actual behavior.
Any sample code if different from the one provided.
Go to Tools -> Python -> Analysis, set your Log Level to Trace, and share the logs.
Thank you for your understanding!
This issue has been moved from a ticket on Developer Community.
Hi,
I have a problem with Visual Studio 2022 / Python. I am using Visual Studio to write and debug Python code.
I am not sure if this is a Visual Studio problem or a Python problem or both.
Note that this problem affects both edit mode in Visual Studio and run mode in Visual Studio. In other words, the same errors show up when a Python program is running (using F5 in Visual Studio).
The problem has an easy description, but is rather serious.
I use ‘from HDLmXXX import *’ statements, at the start of some of my Python programs (see 20230130_095849.jpg). That is pretty standard.
20230130_095849.jpg
20230130_095914.jpg
However, the import classes (some of them) are unknown later. See 20230130_095914.jpg.
Why do I get this error? What can I do about this?
Original Comments
Feedback Bot on 1/30/2023, 06:14 PM:
(private comment, text removed)
pschaeffer on 2/2/2023, 05:59 PM:
(private comment, text removed)
Original Solutions
(no solutions)