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

"..." is not iterable when calling a conditional return function #54

Closed
PrateekArya opened this issue Jul 5, 2020 · 5 comments
Closed
Labels
fixed in next version (main) A fix has been implemented and will appear in an upcoming version

Comments

@PrateekArya
Copy link

Environment data

  • Language Server version: 2020.6.1
  • OS and version: 10 and 1909
  • Python version (& distribution if applicable, e.g. Anaconda): Anaconda 3, python 3.6.5 64-bit

Expected behaviour

No error

Actual behaviour

image

Logs

[FG] parsing: d:\...\main4NewAdm.py (234ms)
[FG] binding: d:\...\main4NewAdm.py (10ms)
[FG] parsing: C:\Users\...\AppData\Local\Continuum\anaconda3\lib\site-packages\IPython\display.py (16ms)
[FG] binding: C:\Users\...\AppData\Local\Continuum\anaconda3\lib\site-packages\IPython\display.py ...
[FG]   parsing: C:\Users\...\AppData\Local\Continuum\anaconda3\lib\site-packages\IPython\core\display.py (202ms)
[FG]   binding: C:\Users\...\AppData\Local\Continuum\anaconda3\lib\site-packages\IPython\core\display.py (9ms)
[FG]   parsing: C:\Users\...\AppData\Local\Continuum\anaconda3\lib\site-packages\IPython\lib\display.py (75ms)
[FG]   binding: C:\Users\...\AppData\Local\Continuum\anaconda3\lib\site-packages\IPython\lib\display.py (5ms)
[FG] binding: C:\Users\...\AppData\Local\Continuum\anaconda3\lib\site-packages\IPython\display.py (291ms)
IntelliCode: current invocation did not produce any meaningful tokens.
Time taken to get recommendations: 116 ms, Memory increase: 490 KB.
[BG] analyzing: d:\...\main4NewAdm.py ...
[BG]   parsing: d:\...\main4NewAdm.py (221ms)
[BG]   binding: d:\...\main4NewAdm.py (24ms)
[BG]   checking: d:\...\main4NewAdm.py (1776ms)
[BG] analyzing: d:\...\main4NewAdm.py (2021ms)
[FG] parsing: d:\...\main4NewAdm.py (37ms)
[FG] binding: d:\...\main4NewAdm.py (5ms)
[BG] analyzing: d:\...\main4NewAdm.py ...
[BG]   parsing: d:\...\main4NewAdm.py (71ms)
[BG]   binding: d:\...\main4NewAdm.py (3ms)
[BG]   checking: d:\...\main4NewAdm.py (52552ms)
[BG] analyzing: d:\...\main4NewAdm.py (52626ms)

Code Snippet / Additional information

image

@erictraut
Copy link
Contributor

erictraut commented Jul 5, 2020

Thanks for reporting the issue, but there isn't enough information here for me to investigate further. I would need a self-contained code snippet or instructions for how to repro.

Based on the screen shot above, it looks like there is a code path whereby importedStuff can contain None. This will result in an exception if you attempt to assign it a tuple. So without any additional details, it appears that this is a bug in your code that Pylance/Pyright has helped to identify. I recommend looking at the function dPP.importStuff() to determine whether there is a code path by which it returns None. If so, your code should be prepared to deal with that return value.

@PrateekArya
Copy link
Author

PrateekArya commented Jul 5, 2020

I understand your argument about my code possibly returning None which is actually possible (refer the importStuff function below). In that case my code will throw an exception which is what I want it to do. :) But I think if Pylance/Pyright wants to point it out then it should categories it as a warning or information as this is not really an error!

def importStuff(fileName='ExportedObjs', ext='', path=''):

#Adding path splitter if not supplied
if not len(path) == 0 and not path[-2:] == '\\':
    path += '\\'

#Checking extension
if ext == '':
    dotIdx = fileName[-5:].find('.')
    if dotIdx == -1:
        ext = '.pkl'    #Setting default extension
    else:  
        #Extracting extension from file name
        ext = fileName[-5:][dotIdx:]
        fileName = fileName[:-5+dotIdx]

#Reading pickle file
if ext == '.pkl':
    #Reading file
    fRead = open(path + fileName + ext, 'rb')

    importList = []
    #Loading objects one by one
    try:
        while True:
            importList.append(pkl.load(fRead))
    except EOFError:
        fRead.close()
        return importList
elif ext == '.xls' or ext == '.xlsx':
    #Reading excel
    fileObj = pd.ExcelFile(path + fileName + ext)

    data = dict({})
    #Reading all sheets in a Dict
    for sheetName in fileObj.sheet_names:
        data[sheetName] = pd.read_excel(fileObj, sheetName, index_col=False)
    
    if len(data.keys()) == 1:
        return data[sheetName]
    else:
        return data
elif ext == '.csv':
    #Reading csv
    return pd.read_csv(path + fileName + ext)

@erictraut
Copy link
Contributor

This particular diagnostic ("x is not iterable") should be associated with the diagnostic rule "reportGeneralTypeIssues". Currently, it's not. I'll make that change. Because of this, it is reported even if typeCheckingMode is set to "off". It should be reported only if typeCheckingMode is set to "basic" or "strict".

@erictraut erictraut added the fixed in next version (main) A fix has been implemented and will appear in an upcoming version label Jul 5, 2020
@PrateekArya
Copy link
Author

Please feel free to close this then. I'll be on vacations for next two weeks. 🙂

@jakebailey
Copy link
Member

This issue has been fixed in version 2020.7.0, which we've just released. You can find the changelog here: https://github.com/microsoft/pylance-release/blob/master/CHANGELOG.md#202070-9-july-2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed in next version (main) A fix has been implemented and will appear in an upcoming version
Projects
None yet
Development

No branches or pull requests

3 participants