microsoft / pylance-release

Documentation and issues for Pylance
Creative Commons Attribution 4.0 International
1.69k stars 770 forks source link

Code error reporting crashes after adding the `while` keyword to a specific script. #1686

Closed Kallamez closed 3 years ago

Kallamez commented 3 years ago

Environment data

Expected behaviour

A green underline appearing underneath an undefined variable or a red underline appearing underneath incomplete expression, regardless of it being on the file itself, or any other script open in VSCode.

Actual behaviour

Both kinds of highlights completely stop working in the entire software. Any files already opened with such highlights retain them, even if the bad parts are corrected or removed, and any new errors won't be detected. I have to close the offending script, then restart VSCode for it to come back, but if I reopen the problematic script, it happens again.

Logs

Log of the Python Language Server. First opened VSCode, then opened the problematic script

[Info  - 2:37:44 PM] Pylance language server 2021.8.1 (pyright abd41b72) starting
[Info  - 2:37:44 PM] Server root directory: c:\Users\Tosh0kan\.vscode\extensions\ms-python.vscode-pylance-2021.8.1\dist
[Info  - 2:37:44 PM] No configuration file found.
[Info  - 2:37:44 PM] No pyproject.toml file found.
[Info  - 2:37:44 PM] Setting pythonPath for service "Coding": "C:\Users\Tosh0kan\AppData\Local\Programs\Python\Python39\python.exe"
[Info  - 2:37:44 PM] Assuming Python version 3.9
[Info  - 2:37:44 PM] Assuming Python platform Windows
Search paths for h:\01 Libraries\Documents\Tosh0kan Studios\Coding
  c:\Users\Tosh0kan\.vscode\extensions\ms-python.vscode-pylance-2021.8.1\dist\typeshed-fallback\stdlib
  h:\01 Libraries\Documents\Tosh0kan Studios\Coding
  h:\01 Libraries\Documents\Tosh0kan Studios\Coding\typings
  c:\Users\Tosh0kan\.vscode\extensions\ms-python.vscode-pylance-2021.8.1\dist\typeshed-fallback\stubs\...
  c:\Users\Tosh0kan\.vscode\extensions\ms-python.vscode-pylance-2021.8.1\dist\bundled\stubs
  c:\Users\Tosh0kan\AppData\Local\Programs\Python\Python39\DLLs
  c:\Users\Tosh0kan\AppData\Local\Programs\Python\Python39\Lib
  c:\Users\Tosh0kan\AppData\Local\Programs\Python\Python39
  c:\Users\Tosh0kan\AppData\Roaming\Python\Python39\site-packages
  c:\Users\Tosh0kan\AppData\Local\Programs\Python\Python39\Lib\site-packages
[Info  - 2:37:45 PM] Searching for source files
[Info  - 2:37:45 PM] Found 14 source files
[Info  - 2:37:45 PM] Background analysis(1) root directory: c:\Users\Tosh0kan\.vscode\extensions\ms-python.vscode-pylance-2021.8.1\dist
[Info  - 2:37:45 PM] Background analysis(1) started
Background analysis message: setConfigOptions
Background analysis message: setImportResolver
Background analysis message: ensurePartialStubPackages
Background analysis message: setTrackedFiles
Background analysis message: markAllFilesDirty
Background analysis message: analyze
Background analysis message: setFileOpened
[FG] parsing: h:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\Planet Generator.py (128ms)
[FG] parsing: c:\Users\Tosh0kan\.vscode\extensions\ms-python.vscode-pylance-2021.8.1\dist\typeshed-fallback\stdlib\builtins.pyi [fs read 3ms] (109ms)
[FG] binding: c:\Users\Tosh0kan\.vscode\extensions\ms-python.vscode-pylance-2021.8.1\dist\typeshed-fallback\stdlib\builtins.pyi (51ms)
[FG] binding: h:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\Planet Generator.py (9ms)
Background analysis message: getDiagnosticsForRange
Background analysis message: analyze
[BG(1)] analyzing: h:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\Planet Generator.py ...
[BG(1)]   parsing: h:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\Planet Generator.py (92ms)
[BG(1)]   parsing: c:\Users\Tosh0kan\.vscode\extensions\ms-python.vscode-pylance-2021.8.1\dist\typeshed-fallback\stdlib\builtins.pyi [fs read 3ms] (111ms)
[BG(1)]   binding: c:\Users\Tosh0kan\.vscode\extensions\ms-python.vscode-pylance-2021.8.1\dist\typeshed-fallback\stdlib\builtins.pyi (48ms)
[BG(1)]   binding: h:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\Planet Generator.py (10ms)
[BG(1)]   checking: h:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\Planet Generator.py ...
[BG(1)]     parsing: c:\Users\Tosh0kan\.vscode\extensions\ms-python.vscode-pylance-2021.8.1\dist\typeshed-fallback\stdlib\typing.pyi [fs read 2ms] (38ms)
[BG(1)]     binding: c:\Users\Tosh0kan\.vscode\extensions\ms-python.vscode-pylance-2021.8.1\dist\typeshed-fallback\stdlib\typing.pyi (17ms)
[BG(1)]     parsing: c:\Users\Tosh0kan\.vscode\extensions\ms-python.vscode-pylance-2021.8.1\dist\typeshed-fallback\stdlib\_typeshed\__init__.pyi [fs read 0ms] (10ms)
[BG(1)]     binding: c:\Users\Tosh0kan\.vscode\extensions\ms-python.vscode-pylance-2021.8.1\dist\typeshed-fallback\stdlib\_typeshed\__init__.pyi (2ms)
[BG(1)]     parsing: c:\Users\Tosh0kan\.vscode\extensions\ms-python.vscode-pylance-2021.8.1\dist\typeshed-fallback\stdlib\typing_extensions.pyi [fs read 0ms] (3ms)
[BG(1)]     binding: c:\Users\Tosh0kan\.vscode\extensions\ms-python.vscode-pylance-2021.8.1\dist\typeshed-fallback\stdlib\typing_extensions.pyi (2ms)
[BG(1)]     parsing: c:\Users\Tosh0kan\.vscode\extensions\ms-python.vscode-pylance-2021.8.1\dist\typeshed-fallback\stdlib\random.pyi [fs read 0ms] (4ms)
[BG(1)]     binding: c:\Users\Tosh0kan\.vscode\extensions\ms-python.vscode-pylance-2021.8.1\dist\typeshed-fallback\stdlib\random.pyi (3ms)
[BG(1)]     parsing: c:\Users\Tosh0kan\.vscode\extensions\ms-python.vscode-pylance-2021.8.1\dist\typeshed-fallback\stdlib\string.pyi [fs read 0ms] (1ms)
[BG(1)]     binding: c:\Users\Tosh0kan\.vscode\extensions\ms-python.vscode-pylance-2021.8.1\dist\typeshed-fallback\stdlib\string.pyi (1ms)
[BG(1)]     parsing: c:\Users\Tosh0kan\.vscode\extensions\ms-python.vscode-pylance-2021.8.1\dist\bundled\stubs\pandas\__init__.pyi [fs read 0ms] (5ms)
[BG(1)]     binding: c:\Users\Tosh0kan\.vscode\extensions\ms-python.vscode-pylance-2021.8.1\dist\bundled\stubs\pandas\__init__.pyi (2ms)
[BG(1)]     parsing: c:\Users\Tosh0kan\.vscode\extensions\ms-python.vscode-pylance-2021.8.1\dist\bundled\stubs\pandas\io\api.pyi [fs read 0ms] (45ms)
[BG(1)]     binding: c:\Users\Tosh0kan\.vscode\extensions\ms-python.vscode-pylance-2021.8.1\dist\bundled\stubs\pandas\io\api.pyi (1ms)
[BG(1)]     parsing: c:\Users\Tosh0kan\.vscode\extensions\ms-python.vscode-pylance-2021.8.1\dist\bundled\stubs\pandas\io\parsers.pyi [fs read 0ms] (24ms)
[BG(1)]     binding: c:\Users\Tosh0kan\.vscode\extensions\ms-python.vscode-pylance-2021.8.1\dist\bundled\stubs\pandas\io\parsers.pyi (5ms)
[BG(1)]     parsing: c:\Users\Tosh0kan\.vscode\extensions\ms-python.vscode-pylance-2021.8.1\dist\bundled\stubs\pandas\_typing.pyi [fs read 0ms] (24ms)
[BG(1)]     binding: c:\Users\Tosh0kan\.vscode\extensions\ms-python.vscode-pylance-2021.8.1\dist\bundled\stubs\pandas\_typing.pyi (1ms)
[BG(1)]     parsing: c:\Users\Tosh0kan\.vscode\extensions\ms-python.vscode-pylance-2021.8.1\dist\typeshed-fallback\stdlib\os\__init__.pyi [fs read 0ms] (15ms)
[BG(1)]     binding: c:\Users\Tosh0kan\.vscode\extensions\ms-python.vscode-pylance-2021.8.1\dist\typeshed-fallback\stdlib\os\__init__.pyi (8ms)
[BG(1)]     parsing: c:\Users\Tosh0kan\.vscode\extensions\ms-python.vscode-pylance-2021.8.1\dist\typeshed-fallback\stdlib\abc.pyi [fs read 0ms] (3ms)
[BG(1)]     binding: c:\Users\Tosh0kan\.vscode\extensions\ms-python.vscode-pylance-2021.8.1\dist\typeshed-fallback\stdlib\abc.pyi (1ms)
[BG(1)]     parsing: c:\Users\Tosh0kan\.vscode\extensions\ms-python.vscode-pylance-2021.8.1\dist\typeshed-fallback\stdlib\io.pyi [fs read 0ms] (4ms)
[BG(1)]     binding: c:\Users\Tosh0kan\.vscode\extensions\ms-python.vscode-pylance-2021.8.1\dist\typeshed-fallback\stdlib\io.pyi (3ms)
[BG(1)]     parsing: c:\Users\Tosh0kan\.vscode\extensions\ms-python.vscode-pylance-2021.8.1\dist\typeshed-fallback\stdlib\mmap.pyi [fs read 1ms] (6ms)
[BG(1)]     binding: c:\Users\Tosh0kan\.vscode\extensions\ms-python.vscode-pylance-2021.8.1\dist\typeshed-fallback\stdlib\mmap.pyi (2ms)
[BG(1)]     parsing: c:\Users\Tosh0kan\.vscode\extensions\ms-python.vscode-pylance-2021.8.1\dist\typeshed-fallback\stdlib\datetime.pyi [fs read 0ms] (10ms)
[BG(1)]     binding: c:\Users\Tosh0kan\.vscode\extensions\ms-python.vscode-pylance-2021.8.1\dist\typeshed-fallback\stdlib\datetime.pyi (5ms)
[BG(1)]     parsing: c:\Users\Tosh0kan\.vscode\extensions\ms-python.vscode-pylance-2021.8.1\dist\bundled\stubs\pandas\core\frame.pyi [fs read 1ms] (100ms)
[BG(1)]     binding: c:\Users\Tosh0kan\.vscode\extensions\ms-python.vscode-pylance-2021.8.1\dist\bundled\stubs\pandas\core\frame.pyi (33ms)
[BG(1)]     parsing: c:\Users\Tosh0kan\.vscode\extensions\ms-python.vscode-pylance-2021.8.1\dist\bundled\stubs\pandas\core\generic.pyi [fs read 0ms] (26ms)
[BG(1)]     binding: c:\Users\Tosh0kan\.vscode\extensions\ms-python.vscode-pylance-2021.8.1\dist\bundled\stubs\pandas\core\generic.pyi (1ms)
[BG(1)]     parsing: c:\Users\Tosh0kan\.vscode\extensions\ms-python.vscode-pylance-2021.8.1\dist\bundled\stubs\pandas\core\base.pyi [fs read 0ms] (4ms)
[BG(1)]     binding: c:\Users\Tosh0kan\.vscode\extensions\ms-python.vscode-pylance-2021.8.1\dist\bundled\stubs\pandas\core\base.pyi (1ms)
[BG(1)]     parsing: c:\Users\Tosh0kan\.vscode\extensions\ms-python.vscode-pylance-2021.8.1\dist\bundled\stubs\pandas\core\accessor.pyi [fs read 0ms] (1ms)
[BG(1)]     binding: c:\Users\Tosh0kan\.vscode\extensions\ms-python.vscode-pylance-2021.8.1\dist\bundled\stubs\pandas\core\accessor.pyi (0ms)
[BG(1)]     parsing: c:\Users\Tosh0kan\.vscode\extensions\ms-python.vscode-pylance-2021.8.1\dist\bundled\stubs\pandas\core\indexing.pyi [fs read 0ms] (6ms)
[BG(1)]     binding: c:\Users\Tosh0kan\.vscode\extensions\ms-python.vscode-pylance-2021.8.1\dist\bundled\stubs\pandas\core\indexing.pyi (0ms)
[BG(1)]     parsing: c:\Users\Tosh0kan\.vscode\extensions\ms-python.vscode-pylance-2021.8.1\dist\typeshed-fallback\stdlib\collections\__init__.pyi [fs read 1ms] (5ms)
[BG(1)]     binding: c:\Users\Tosh0kan\.vscode\extensions\ms-python.vscode-pylance-2021.8.1\dist\typeshed-fallback\stdlib\collections\__init__.pyi ...
[BG(1)]       parsing: c:\Users\Tosh0kan\.vscode\extensions\ms-python.vscode-pylance-2021.8.1\dist\typeshed-fallback\stdlib\_collections_abc.pyi [fs read 0ms] (1ms)
[BG(1)]       binding: c:\Users\Tosh0kan\.vscode\extensions\ms-python.vscode-pylance-2021.8.1\dist\typeshed-fallback\stdlib\_collections_abc.pyi (0ms)
[BG(1)]     binding: c:\Users\Tosh0kan\.vscode\extensions\ms-python.vscode-pylance-2021.8.1\dist\typeshed-fallback\stdlib\collections\__init__.pyi (5ms)
[BG(1)]     parsing: c:\Users\Tosh0kan\.vscode\extensions\ms-python.vscode-pylance-2021.8.1\dist\typeshed-fallback\stdlib\collections\abc.pyi [fs read 0ms] (0ms)
[BG(1)]     binding: c:\Users\Tosh0kan\.vscode\extensions\ms-python.vscode-pylance-2021.8.1\dist\typeshed-fallback\stdlib\collections\abc.pyi (0ms)
[BG(1)]     parsing: c:\Users\Tosh0kan\AppData\Local\Programs\Python\Python39\Lib\site-packages\numpy\__init__.pyi [fs read 1ms] (107ms)
[BG(1)]     binding: c:\Users\Tosh0kan\AppData\Local\Programs\Python\Python39\Lib\site-packages\numpy\__init__.pyi (33ms)

Code Snippet / Additional information

GIF of the highlight working fine on the script when it doesn't have the while loop: https://i.imgur.com/WMxcXp5.gif

GIF of the highlight not working at all the same script when the while loop is present: https://i.imgur.com/IpGbLoT.gif

import random
from string import ascii_uppercase
from pandas import read_csv
from numpy import arange

error_message = "Variable undefined"

def csv_parser(path):
    a = read_csv(path, header=0, sep=";")
    return a

def rollDice(numDice):
    results = []
    for x in range(numDice):
        results.append(random.choice(range(1,7)))
    return sum(results)

old_results = ""

loop_count = 0

while loop_count < 3:
    letters = ascii_uppercase
    numbers = "0123456789"
    letters_numbers = letters + numbers
    planet_name = f"""{random.choice(letters)}T{random.choice(letters_numbers)}-{random.choice(numbers)}{random.choice(numbers)}{random.choice(numbers)}"""

    #STEP 2: World Type (pg 74)
    overall_type_table = csv_parser(R"H:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\Tables\1 - Overall Type Table.csv")
    world_type_table = csv_parser(R"H:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\Tables\2 - World Type Table.csv")

    overall_type_roll = rollDice(3)
    #print("Ovr Type Roll: " + str(overall_type_roll))

    world_type_roll = rollDice(3)
    #print("World Type Roll" + str(world_type_roll)) 

    world_type = error_message
    rowN = 0
    for x in range(3): #Overall Type Loop
        if overall_type_roll <= overall_type_table.iloc[rowN,0]:
            overall_type = overall_type_table.iloc[rowN,1]
            break

        rowN = rowN + 1 

    rowN = 0   
    if overall_type == overall_type_table.iloc[0,1]: #World Type loop for Hostiles
        for x in range(16):
            if world_type_roll <= world_type_table.iloc[rowN,0]:
                world_type = world_type_table.iloc[rowN,1]
                break
            rowN = rowN + 1

    elif overall_type == overall_type_table.iloc[1,1]: #World Type loop for Barrens
        for x in range(16):
            if world_type_roll <= world_type_table.iloc[rowN,0]:
                world_type = world_type_table.iloc[rowN,2]
                break
            rowN = rowN + 1

    elif overall_type == overall_type_table.iloc[2,1]: #World Type loop for Gardens
        for x in range(16):
            if world_type_roll <= world_type_table.iloc[rowN,0]:
                world_type = world_type_table.iloc[rowN,3]
                break
            rowN = rowN + 1

    overall_type = "Hostile"
    world_type = "Standard (Chthonian)"
    #world_type = "Asteroid Belt"
    #world_type = "Tiny (Ice)"

    #STEP 3: Atmosphere (pg 78)
    #Atmospheric Mass

    atmo_mass_roll = rollDice(3)
    if (world_type == world_type_table.iloc[9,2]) or (world_type == world_type_table.iloc[5,2]) or (world_type == world_type_table.iloc[3,2]) or (world_type == world_type_table.iloc[7,2]) or (world_type == world_type_table.iloc[0,2]) or (world_type == world_type_table.iloc[13,2]) or (world_type == world_type_table.iloc[6,1]) or (world_type == world_type_table.iloc[1,1]) or (world_type == world_type_table.iloc[15,1]):
        atmo_mass = 0

    else:
        atmo_mass = (atmo_mass_roll / 10) + (random.choice(range(-5,5)) / 100)

    #Atmospheric Composition
    atmo_comp_roll = rollDice(3)

    if (world_type == world_type_table.iloc[9,2]) or (world_type == world_type_table.iloc[5,2]) or (world_type == world_type_table.iloc[3,2]) or (world_type == world_type_table.iloc[7,2]) or (world_type == world_type_table.iloc[0,2]) or (world_type == world_type_table.iloc[13,2]) or (world_type == world_type_table.iloc[6,1]) or (world_type == world_type_table.iloc[1,1]) or (world_type == world_type_table.iloc[15,1]):
        atmo_comp = "Inexistent"

    elif (world_type == world_type_table.iloc[1,2]):
        if atmo_comp_roll <= 15:
            atmo_comp = "Nitrogen and Methane (Suffocating and Mildly Toxic)"
        else:
            atmo_comp = "Nitrogen and Methane (Suffocating and Highly Toxic)"

    elif (world_type == world_type_table.iloc[9,1]):
        atmo_comp = "Nitrogen, Ammonia and Methane (Suffocating, Lethally Toxic and Corrosive)"

    elif (world_type == world_type_table.iloc[12,2]):
        if atmo_comp_roll <= 12:
            atmo_comp = "Nitrogen and Carbon Dioxide (Suffocating)"
        else:
            atmo_comp = "Nitrogen and Carbon Dioxide (Suffocating and Mildly Toxic)"

    elif (world_type == world_type_table.iloc[11,2]):
        if atmo_comp_roll <= 12:
            atmo_comp = "Nitrogen and Carbon Dioxide (Suffocating)"
        else:
            atmo_comp = "Nitrogen and Carbon Dioxide (Suffocating and Mildly Toxic)"

    elif (world_type == world_type_table.iloc[13,3]):
        atmo_comp = "Nitrogen and Free Oxygen"

    elif (world_type == world_type_table.iloc[3,1]) or (world_type == world_type_table.iloc[13,1]):
        atmo_comp = "Inexistent"

    elif (world_type == world_type_table.iloc[11,1]):
        atmo_comp = "Helium Gas, Ammonia and Methane (Suffocating, Lethally Toxic and Corrosive"

    elif (world_type == world_type_table.iloc[15,2]) or world_type_table.iloc[14,2]:
        atmo_comp = "Helium and Nitrogen Gases (Suffocating and Highly Toxic"

    elif (world_type == world_type_table.iloc[15,3]):
        atmo_comp = "Nitrogen, Noble Gases and Free Oxygen"

    #Marginal Atmospheres
    marg_atmo_table = csv_parser(R"H:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\Tables\4 - Marginal Atmospheres Table.csv")

    marg_atmo_presence_roll = rollDice(3)
    marg_atmo_roll = rollDice(3)

    rowN = 0
    if ("Garden" in world_type) and marg_atmo_presence_roll >= 12:
        for x in range(9):
            if marg_atmo_roll <= marg_atmo_table.iloc[rowN,0]:
                atmo_comp = atmo_comp + marg_atmo_table.iloc[rowN,1]
                break
            rowN = rowN + 1

    #STEP 4: Hydrographic Coverage 
    hydrocover_math = error_message
    if (world_type == world_type_table.iloc[9,2]) or (world_type == world_type_table.iloc[5,2]) or (world_type == world_type_table.iloc[3,2]) or (world_type == world_type_table.iloc[7,2]) or (world_type == world_type_table.iloc[0,2]) or (world_type == world_type_table.iloc[13,2]) or (world_type == world_type_table.iloc[6,1]) or (world_type == world_type_table.iloc[1,1]) or (world_type == world_type_table.iloc[15,1]):
        hydrocover_math = 0
        hydrocover = str(0) + "%"

    elif (world_type == world_type_table.iloc[1,2]):
        hydrocover_math = (rollDice(1) + 2) * 10
        hydrocover = str(hydrocover_math) + "% (Hydrocarbons)"

    elif (world_type == world_type_table.iloc[9,1]) or (world_type == world_type_table.iloc[11,1]):
        hydrocover_math = (rollDice(2) * 10)
        if hydrocover_math > 100:
            hydrocover_math = 100
        hydrocover = str(hydrocover_math) + "% (Ammonia + Water)"

    elif (world_type == world_type_table.iloc[12,2]) or (world_type == world_type_table.iloc[15,2]):
        hydrocover_math = (rollDice(2) - 10) * 10
        if hydrocover_math < 0:
            hydrocover_math = 0        
        hydrocover = str(hydrocover_math) + "% (Water; Temporary)"

    elif (world_type == world_type_table.iloc[11,2]) or (world_type == world_type_table.iloc[13,3]):
        hydrocover_math = (rollDice(2) + 4) * 10
        if hydrocover_math > 100:
            hydrocover_math = 100
        hydrocover = str(hydrocover_math) + "% (Water)"

    elif (world_type == world_type_table.iloc[14,2]) or (world_type == world_type_table.iloc[15,3]):
        hydrocover_math = (rollDice(2) + 6) * 10
        if hydrocover_math > 100:
            hydrocover_math = 100
        hydrocover = str(hydrocover_math) + "% (Water)"

    elif (world_type == world_type_table.iloc[3,1]) or (world_type == world_type_table.iloc[13,1]):
        hydrocover_math = (rollDice(2) - 7) * 10
        if hydrocover_math < 0:
            hydrocover_math = 0
            hydrocover = str(0) + "%"

        else:
            hydrocover = str(hydrocover_math) + "% (Water; Temporary)"

        if hydrocover_math > 0:
            atmo_comp = "Nitrogen, Water Vapor and Free Oxygen (Suffocating, Lethaly Toxic and Corrosive)"

        else:
            atmo_comp = "Carbon Dioxide (Suffocating, Lethaly Toxic and Corrosive)"

    #STEP 5: Climate (pg 83)
    avg_surf_temp_table = csv_parser(R"H:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\Tables\5 - Average Surface Temperature Table.csv")
    world_climate_table = csv_parser(R"H:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\Tables\6 - World Climate Table.csv")
    temp_factors_table = csv_parser(R"H:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\Tables\7 - Temperature Factors Table.csv")

    #Climate Type
    avg_surf_temp_roll = (rollDice(3) - 3) 

    rowN = 0 #Finding average surface temperature
    for x in range(20):
        if world_type == avg_surf_temp_table.iloc[rowN,0]:
            avg_surf_temp = ((avg_surf_temp_roll * avg_surf_temp_table.iloc[rowN,3]) + avg_surf_temp_table.iloc[rowN,1])
            break

        rowN = rowN + 1

    rowN = 0 #Defining world climate
    for x in range(12):
        if avg_surf_temp <= world_climate_table.iloc[rowN,1]:
            world_climate = world_climate_table.iloc[rowN,2]
            break

        rowN = rowN + 1

    #Determining Blackbody Temperature
    rowN = 0 
    for x in range(20): #Defining Absorption and Greenhouse factor to calculate blackbody temperature
        if world_type == temp_factors_table.iloc[rowN,0]:
            absorp_factor = temp_factors_table.iloc[rowN,1]
            greenhouse_factor = temp_factors_table.iloc[rowN,2]
            break

        elif (("Ocean" in world_type) or ("Garden" in world_type)) and (hydrocover_math <= 20):
            absorp_factor = temp_factors_table.iloc[12,1]
            greenhouse_factor = temp_factors_table.iloc[12,2]
            break

        elif (("Ocean" in world_type) or ("Garden" in world_type)) and (hydrocover_math <= 50):
            absorp_factor = temp_factors_table.iloc[13,1]
            greenhouse_factor = temp_factors_table.iloc[13,2]
            break

        elif (("Ocean" in world_type) or ("Garden" in world_type)) and (hydrocover_math <= 90):
            absorp_factor = temp_factors_table.iloc[14,1]
            greenhouse_factor = temp_factors_table.iloc[14,2]
            break

        elif (("Ocean" in world_type) or ("Garden" in world_type)) and (hydrocover_math <= float("inf")):
            absorp_factor = temp_factors_table.iloc[15,1]
            greenhouse_factor = temp_factors_table.iloc[15,2]
            break

        rowN = rowN + 1

    blackbody_correction = absorp_factor * (1 + (atmo_mass * greenhouse_factor))

    blackbody_temp = avg_surf_temp / blackbody_correction

    #STEP 6: World Size (pg 84)
    world_density_table = csv_parser(R"H:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\Tables\8 - World Density Table.csv")

    if "Asteroid Belt" not in world_type:
        if ("Sulfur" in world_type) or ("Ice" in world_type) or ("Hadean" in world_type) or ("Ammonia" in world_type):
            core_type = "Icy Core"

        elif ("Rock" in world_type):
            core_type = "Small Iron Core"

        else:
            core_type = "Large Iron Core"

        world_density_roll = rollDice(3)

        rowN = 0
        for x in range(5):
            if world_density_roll <= world_density_table.iloc[rowN,0]:
                if "Icy" in core_type:
                    world_density_ratio = world_density_table.iloc[rowN,1] + (random.choice(range(-5,5)) / 100)
                    break

                elif "Small" in core_type: 
                    world_density_ratio = world_density_table.iloc[rowN,2] + (random.choice(range(-5,5)) / 100)
                    break

                elif "Large" in core_type:
                    world_density_ratio = world_density_table.iloc[rowN,3] + (random.choice(range(-5,5)) / 100)
                    break

            rowN = rowN + 1

        world_density_cm3 = world_density_ratio * 5.52

        #Diameter and Surface Gravity
        size_constraints_table = csv_parser(R"H:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\Tables\9 - Size Constraints Table.csv")

        diameter_roll = rollDice(2) - 2
        min_constraint = "You shouldn't be getting this output."
        max_constraint = "You shouldn't be getting this output."

        if "Large" in world_type:
            min_constraint = size_constraints_table.iloc[0,1]
            max_constraint = size_constraints_table.iloc[0,2]

        elif "Standard" in world_type:
            min_constraint = size_constraints_table.iloc[1,1]
            max_constraint = size_constraints_table.iloc[1,2]

        elif "Small" in world_type:
            min_constraint = size_constraints_table.iloc[2,1]
            max_constraint = size_constraints_table.iloc[2,2]

        elif "Tiny" in world_type:
            min_constraint = size_constraints_table.iloc[3,1]
            max_constraint = size_constraints_table.iloc[3,2]

        min_diameter = ((blackbody_temp / world_density_ratio) ** 1/2) * min_constraint
        max_diameter = ((blackbody_temp / world_density_ratio) ** 1/2) * max_constraint

        world_diameter_ratio = (diameter_roll * ((max_diameter - min_diameter)/10)) + min_constraint
        world_diameter_meter = world_diameter_ratio * 6378

        surface_gravity = world_density_ratio * world_diameter_ratio
        gravity_acceleration = surface_gravity * 9.807

        world_mass = world_density_ratio * (world_diameter_ratio ** 3)

    else:
        core_type = "Not Applicable"
        world_density_roll = "Not Applicable"
        world_density_ratio = "Not Applicable"
        world_density_cm3 = "Not Applicable"
        diameter_roll = "Not Applicable"
        min_constraint = "Not Applicable"
        max_constraint = "Not Applicable"
        min_diameter = "Not Applicable"
        max_diameter = "Not Applicable"
        world_diameter_ratio = "Not Applicable"
        world_diameter_meter = "Not Applicable"
        surface_gravity = "Not Applicable"
        gravity_acceleration = "Not Applicable"
        world_mass = "Not Applicable"

    #Determining Atmospheric Pressure
    pressure_factors_table = csv_parser(R"H:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\Tables\10 - Pressure Factors Table.csv")
    atmo_pressure_table = csv_parser(R"H:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\Tables\3 - Atmospheric Pressure Categories Table.csv")

    if ("Asteroid" in world_type) or ("Tiny" in world_type) or ("Hadean" in world_type):
        atmo_pressure = 0

    elif ("Rock" in world_type) or ("Chthonian" in world_type):
        atmo_pressure = (random.choice(arange(0,0.01,0.001)))

    else:
        rowN = 0
        for x in range(11):
            if world_type in pressure_factors_table.iloc[rowN,0]:
                pressure_factor = pressure_factors_table.iloc[rowN,1]
                break
            rowN = rowN + 1

        atmo_pressure = atmo_mass * pressure_factor * surface_gravity

    if atmo_pressure == 0:
        atmo_pressure_category = "(Non-Existent)"

    else:
        rowN = 0
        for x in range(7):
            if atmo_pressure <= atmo_pressure_table.iloc[rowN,1]:
                atmo_pressure_category = atmo_pressure_table.iloc[rowN,2]
                break
            rowN = rowN + 1

    #STEP 7: Resources and Habitability
    resources_value_table = csv_parser(R"H:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\Tables\11 - Resource Value Table.csv")

    resources_value_roll = rollDice(3)

    rowN = 0
    if "Asteroid" in world_type:
        for x in range(11):
            if resources_value_roll <= resources_value_table.iloc[rowN,0]:
                resources_value_mod = resources_value_table.iloc[rowN,3]
                resources_value_category = resources_value_table.iloc[rowN,2]
                break
            rowN = rowN +1

    else:
        for x in range(11):
            if resources_value_roll <= resources_value_table.iloc[rowN,1]:
                resources_value_mod = resources_value_table.iloc[rowN,3]
                resources_value_category = resources_value_table.iloc[rowN,2]
                break
            rowN = rowN +1

    habitability_mod = 0
    if atmo_pressure <= 0.009:
        habitability_mod = 0

    elif "Suffocating" in atmo_comp:
        if ("Toxic" in atmo_comp) and ("Corrosive" in atmo_comp):
            habitability_mod = habitability_mod - 2

        elif ("Toxic" in atmo_comp):
            habitability_mod = habitability_mod - 1

        else:
            habitability_mod = habitability_mod + 0 

    elif ("Frozen" in world_climate) or ("Very" in world_climate) or ("Infernal" in world_climate):
        habitability_mod = habitability_mod + 0 

    elif ("Cold" in world_climate) or ("Hot" in world_climate):
        habitability_mod = habitability_mod +1

    elif ("Chilly" in world_climate) or ("Coll" in world_climate) or ("Normal" in world_climate) or ("Warm" in world_climate) or ("Tropical" in world_climate):
        habitability_mod = habitability_mod +2

    if ("Very Thin" in atmo_pressure_category) or ("Very Dense" in atmo_pressure_category) or ("Superdense" in atmo_pressure_category):
        habitability_mod = habitability_mod + 1

    elif ("Thin" in atmo_pressure_category):
        habitability_mod = habitability_mod + 2

    elif ("Standard" in atmo_pressure_category) or ("Dense" in atmo_pressure_category):
        habitability_mod = habitability_mod + 3

    if marg_atmo_presence_roll <= 11:
        habitability_mod = habitability_mod + 1

    if ("Water" in hydrocover) and not ("Ammonia" in hydrocover) and not ("Temporary" in hydrocover):
        if hydrocover_math <= 59:
            habitability_mod = habitability_mod + 1

        elif hydrocover_math <= 90:
            habitability_mod = habitability_mod + 2

        elif hydrocover_math <= 99:
            habitability_mod = habitability_mod + 1

        else :
            habitability_mod = habitability_mod + 0

    affinity_score = habitability_mod + resources_value_mod

    results = f"""==================================================================

    Name: {planet_name}

    Overall Type Roll: {overall_type_roll} World Type Roll:{world_type_roll}
    World  Type: {world_type} ({overall_type}),

    Atmospheric Mass Roll: {atmo_mass_roll}, Atmospheric Comp Roll: {atmo_comp_roll},
    Marginal Atmosphere Roll: {marg_atmo_presence_roll} Marginal Atmo. Table Roll: {marg_atmo_roll}

    Atmospheric Mass: {atmo_mass}, Atmospheric Composition: {atmo_comp},
    Atmospheric Pressure: {atmo_pressure} ({atmo_pressure_category})

    Hydrographic Math: {hydrocover_math} Hydrographic Cover: {hydrocover}

    Avg. Surf. Temp. Roll: {avg_surf_temp_roll}

    Avg Surf Temp: {avg_surf_temp}, World Climate: {world_climate}

    Absorption Factor: {absorp_factor}, Greenhouse Factor: {greenhouse_factor},
    Blackbody Correction: {blackbody_correction}, Blackbody Temperature: {blackbody_temp}

    World Density Roll: {world_density_roll}
    Core Type: {core_type}, World Density: {world_density_ratio} Earth's or {world_density_cm3}g/cm3

    Diameter Roll: {diameter_roll}
    Min. Constraint: {min_constraint}, Max. Constrain: {max_constraint},
    Min. Diameter: {min_diameter}, Max. Diameter: {max_diameter},
    Diameter : {world_diameter_ratio} Earth's or {world_diameter_meter}m,
    Surface Gravity: {surface_gravity}Gs or {gravity_acceleration} m/s2
    World's Mass: {world_mass}

    Resources Value Roll: {resources_value_roll}
    Resources Value Mod: {resources_value_mod}, Resources Value Category: {resources_value_category}

    Habitability Score: {habitability_mod}, Affinity Score: {affinity_score}
    """

    new_results = old_results + results
    old_results = new_results
    loop_count = loop_count + 1

results = old_results

with open("GURPS Space/output.txt","a") as f:
    write_data = f.write(results)
erictraut commented 3 years ago

Thanks for the bug report. I'm seeing what appears to very slow analysis or perhaps an infinite loop. I'll investigate further to determine the root cause.

Kallamez commented 3 years ago

Further testing: I added the ssss variable and left it undefined just to see what happened. This is the new log:

[FG] completion at h:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\new Planet Generator.py:380:1 [found 121 items] (364ms)
[BG(1)]   checking: h:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\new Planet Generator.py (1456ms)
[BG(1)] analyzing: h:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\new Planet Generator.py (1730ms)
Background analysis message: getSemanticTokens full
[FG] completion at h:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\new Planet Generator.py:380:3 ...
[FG]   parsing: h:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\new Planet Generator.py (22ms)
[FG]   binding: h:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\new Planet Generator.py (6ms)
[FG] completion at h:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\new Planet Generator.py:380:3 [found 3 items] (33ms)
[FG] completion at h:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\new Planet Generator.py:380:4 ...
[FG]   parsing: h:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\new Planet Generator.py (12ms)
[FG]   binding: h:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\new Planet Generator.py (4ms)
[FG] completion at h:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\new Planet Generator.py:380:4 [found 1 items] (20ms)
[FG] parsing: h:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\new Planet Generator.py (15ms)
[FG] binding: h:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\new Planet Generator.py (12ms)
[BG(1)] getSemanticTokens full at h:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\new Planet Generator.py ...
[BG(1)]   parsing: c:\Users\Tosh0kan\.vscode\extensions\ms-python.vscode-pylance-2021.8.1\dist\typeshed-fallback\stdlib\types.pyi [fs read 1ms] (14ms)
[BG(1)]   binding: c:\Users\Tosh0kan\.vscode\extensions\ms-python.vscode-pylance-2021.8.1\dist\typeshed-fallback\stdlib\types.pyi (15ms)
[BG(1)] getSemanticTokens full at h:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\new Planet Generator.py (261822ms)
[Info  - 3:33:29 PM] [BG(1)] Long operation: getSemanticTokens full at h:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\new Planet Generator.py (261822ms)
Background analysis message: getDiagnosticsForRange
Background analysis message: getSemanticTokens range
[BG(1)] getSemanticTokens range 314:0 - 380:0 at h:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\new Planet Generator.py (4ms)
Background analysis message: setFileOpened
Background analysis message: markFilesDirty
Background analysis message: analyze
Background analysis message: setFileOpened
Background analysis message: markFilesDirty
Background analysis message: getSemanticTokens range
[BG(1)] getSemanticTokens range 314:0 - 380:2 at h:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\new Planet Generator.py ...
[BG(1)]   parsing: h:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\new Planet Generator.py (7ms)
[BG(1)]   binding: h:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\new Planet Generator.py (10ms)
[BG(1)] getSemanticTokens range 314:0 - 380:2 at h:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\new Planet Generator.py (17ms)
Background analysis message: setFileOpened
Background analysis message: markFilesDirty
Background analysis message: getSemanticTokens range
[BG(1)] getSemanticTokens range 314:0 - 380:3 at h:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\new Planet Generator.py ...
[BG(1)]   parsing: h:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\new Planet Generator.py (6ms)
[BG(1)]   binding: h:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\new Planet Generator.py (6ms)
[BG(1)] getSemanticTokens range 314:0 - 380:3 at h:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\new Planet Generator.py (12ms)
Background analysis message: setFileOpened
Background analysis message: markFilesDirty
Background analysis message: getSemanticTokens range
[BG(1)] getSemanticTokens range 314:0 - 380:4 at h:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\new Planet Generator.py ...
[BG(1)]   parsing: h:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\new Planet Generator.py (8ms)
[BG(1)]   binding: h:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\new Planet Generator.py (6ms)
[BG(1)] getSemanticTokens range 314:0 - 380:4 at h:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\new Planet Generator.py (15ms)
Background analysis message: setFileOpened
Background analysis message: markFilesDirty
Background analysis message: getSemanticTokens range
[BG(1)] getSemanticTokens range 314:0 - 380:5 at h:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\new Planet Generator.py ...
[BG(1)]   parsing: h:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\new Planet Generator.py (6ms)
[BG(1)]   binding: h:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\new Planet Generator.py (6ms)
[BG(1)] getSemanticTokens range 314:0 - 380:5 at h:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\new Planet Generator.py (236949ms)
[Info  - 3:37:26 PM] [BG(1)] Long operation: getSemanticTokens range 314:0 - 380:5 at h:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\new Planet Generator.py (236949ms)
Background analysis message: analyze
[BG(1)] analyzing: h:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\new Planet Generator.py ...
[BG(1)]   checking: h:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\new Planet Generator.py (142ms)
[BG(1)] analyzing: h:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\new Planet Generator.py (142ms)
Background analysis message: getSemanticTokens delta
[BG(1)] getSemanticTokens delta previousResultId:1629224947469 at h:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\new Planet Generator.py (181ms)
Background analysis message: resumeAnalysis

Apparently, it's taking around 4 minutes for it to process my file.

erictraut commented 3 years ago

Yes, I'm seeing analysis times of about 3 minutes.

The challenge is that this is a single, very complex block of code with multiple nested loops and conditional checks. It also has 71 local variables, none of which have type annotations, so types need to be inferred for all of them based on assigned values. When you place the entire block in a while loop, many of these variables' types depend on each other, so they all need to be solved and re-solved until all of the types converge. The analysis time grows exponentially under these circumstances.

I'll investigate whether there are mitigations we can add to the type analysis engine, but there will be limits to what we can do here.

You can work around the issue by factoring your code into proper subroutines. This will have the side benefit of making the code easier to understand and maintain as well.

Kallamez commented 3 years ago

I see. Yeah, apologies for the messy code. I'm really new to python (just two weeks), so I'll follow your advice and see how that fares. Thank you for the advice. 🙇‍♂️

erictraut commented 3 years ago

I've found some optimizations that allow the type analyzer to avoid a bunch of costly work when analyzing complex nested code flow graphs like the one in this sample. This reduces the analysis time from 178s to under 1s on my machine. This optimization will be in the next release.

Kallamez commented 3 years ago

Amazing! Great work!

jakebailey commented 3 years ago

This issue has been fixed in version 2021.7.0, which we've just released. You can find the changelog here: https://github.com/microsoft/pylance-release/blob/main/CHANGELOG.md#202190-1-september-2021