-
Notifications
You must be signed in to change notification settings - Fork 768
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
An internal error occured while type checking file #4552
Comments
According to telemetry the exception is in Pyright's
@xboxone08, can you share your code with us with steps to reproduce this issue? I wasn't able to reproduce it by deleting the first line of an arbitrary .py file. |
The first line was always an import statement and after deleting, the first word was "from" in another import statement. It didn't matter what was being imported though. |
I'm still not able to repro this. The crash location implies that the issue has something to do with a |
I tried making a new file with a basic game loop and event polling import pygame
from typing import Literal
from win10toast import ToastNotifier
from bot import Bot
notifier = ToastNotifier()
pygame.init()
screen = pygame.display.set_mode((800, 450))
pygame.display.set_caption("Portal")
clock = pygame.time.Clock()
running: bool = True
# Joystick instance_id-s and instances
joysticks: dict[int, pygame.joystick.JoystickType] = {}
# Cell inhabitants' ids mapped to index cell
cells: list[int | Literal['k']] = []
# Robot mapped to cell inhabitant id
bots: dict[int | Literal['k'], Bot] = {}
# Which character is to be typed and where mapped to cell inhabitant id
typing: dict[int | Literal['k'], str] = {'k': ''}
controller_typing = pygame.transform.smoothscale(
pygame.image.load('controller_typing.png'), (140, 140)).convert()
# Game loop
while running:
clock.tick(124) # FPS
for e in pygame.event.get():
if e.type == pygame.JOYAXISMOTION:
if e.axis == 0 and e.instance_id in bots:
bots[e.instance_id].turn = round(e.value - 0.04, 1)
elif e.axis == 1 and e.instance_id in bots:
bots[e.instance_id].forward = round(e.value - 0.04, 1)
elif len(typing[e.instance_id].replace(' ', '')) < 12:
if e.axis == 4 and round(e.value, 1) == 1:
typing[e.instance_id] += '5 '
elif e.axis == 5 and round(e.value, 1) == 1:
typing[e.instance_id] += '6 '
# Keyboard can play (press "enter" to join and "esc" to leave)
elif e.type == pygame.KEYUP:
if (e.key == pygame.K_w or e.key == pygame.K_s) and 'k' in bots:
bots['k'].forward = 0
elif (e.key == pygame.K_a or e.key == pygame.K_d) and 'k' in bots:
bots['k'].turn = 0
elif e.type == pygame.KEYDOWN:
if e.key == pygame.K_w and 'k' in bots:
bots['k'].forward = 1
elif e.key == pygame.K_s and 'k' in bots:
bots['k'].forward = -1
elif e.key == pygame.K_a and 'k' in bots:
bots['k'].turn = -1
elif e.key == pygame.K_d and 'k' in bots:
bots['k'].turn = 1
elif e.key == pygame.K_BACKSPACE:
typing['k'] = typing['k'][:-2]
elif (e.key == pygame.K_RETURN or e.key == pygame.K_KP_ENTER):
if 'k' not in cells and len(cells) < 8:
cells.append('k')
elif len(typing['k'].replace(' ', '')) == 12 and 'k' not in bots:
text = typing['k'].replace(' ', '')
ip = text[:3].lstrip('0') + '.' + text[3:6].lstrip('0') + \
'.' + text[6:9].lstrip('0') + \
'.' + text[9:12].lstrip('0')
while ip.find('..') != -1:
ip = ip[:ip.find('..') + 1] + '0' + \
ip[ip.find('..') + 1:]
try:
bots[e.instance_id] = Bot(ip)
except OSError:
notifier.show_toast(
"IP Not Found", f"Couldn't find a robot with that IP ({ip}). Are you in the same LAN as it?", threaded=True)
elif e.key == pygame.K_ESCAPE and 'k' in cells:
cells.remove('k')
bots.pop('k', None)
typing.pop('k', None)
elif e.type == pygame.TEXTINPUT and e.text in ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9') and len(typing['k'].replace(' ', '')) < 12 and 'k' in cells:
typing['k'] += e.text + ' '
elif e.type == pygame.JOYHATMOTION:
if e.hat == 0 and len(typing[e.instance_id].replace(' ', '')) < 12:
if e.value == (0, 1):
typing[e.instance_id] += '1 '
elif e.value == (-1, 0):
typing[e.instance_id] += '2 '
elif e.value == (0, -1):
typing[e.instance_id] += '3 '
elif e.value == (1, 0):
typing[e.instance_id] += '4 '
elif e.type == pygame.JOYBUTTONDOWN:
if len(typing[e.instance_id].replace(' ', '')) < 12:
if e.button == 4:
typing[e.instance_id] += '7 '
elif e.button == 5:
typing[e.instance_id] += '8 '
elif e.button == 3:
typing[e.instance_id] += '9 '
elif e.button == 2:
typing[e.instance_id] += '0 '
# Backspace
if e.button == 1:
typing[e.instance_id] = typing[e.instance_id][:-2]
# Enter
elif e.button == 7:
if len(typing[e.instance_id].replace(' ', '')) == 12 and 'k' not in bots:
text = typing[e.instance_id].replace(' ', '')
ip: str = text[:3].lstrip('0') + '.' + text[3:6].lstrip('0') + \
'.' + text[6:9].lstrip('0') + \
'.' + text[9:12].lstrip('0')
while ip.find('..') != -1:
ip = ip[:ip.find('..') + 1] + '0' + \
ip[ip.find('..') + 1:]
try:
bots[e.instance_id] = Bot(ip)
except OSError:
notifier.show_toast(
"IP Not Found", f"Couldn't find a robot with that IP ({ip}). Are you in the same LAN as it?", threaded=True)
# Update player list dynamically
elif e.type == pygame.JOYDEVICEADDED and len(cells) < 8:
joystick = pygame.joystick.Joystick(e.device_index)
joysticks[joystick.get_instance_id()] = joystick
cells.append(joystick.get_instance_id())
typing[joystick.get_instance_id()] = ''
elif e.type == pygame.JOYDEVICEREMOVED:
del joysticks[e.instance_id]
bots.pop(e.instance_id, None)
cells.remove(e.instance_id)
elif e.type == pygame.QUIT: # Close cleanly
running = False
for bot in bots.values():
bot.drive()
screen.fill((255, 255, 255))
pygame.draw.line(screen, (0, 0, 0), (200, 0), (200, 450), 2)
pygame.draw.line(screen, (0, 0, 0), (400, 0), (400, 450), 2)
pygame.draw.line(screen, (0, 0, 0), (600, 0), (600, 450), 2)
pygame.draw.line(screen, (0, 0, 0), (0, 225), (800, 225), 2)
pygame.draw.rect(screen, (0, 0, 0), pygame.Rect(
0, 0, 800, 450), 2, border_bottom_left_radius=5, border_bottom_right_radius=5)
font = pygame.font.Font(None, 18)
small_font = pygame.font.Font(None, 14)
# Coords of index # cell
cell_coords: tuple[tuple[int, int], tuple[int, int], tuple[int, int], tuple[int, int], tuple[int, int], tuple[int, int],
tuple[int, int], tuple[int, int]] = ((5, 25), (205, 25), (405, 25), (605, 25), (5, 250), (205, 250), (405, 250), (605, 250))
for cell in cells:
cell_name = "Keyboard" if cell == 'k' else "Controller #" + \
str(cell + 1) # type: ignore
screen.blit(font.render(cell_name, True, (0, 0, 0)),
cell_coords[cells.index(cell)])
if bots.get(cell) is None:
screen.blits(((font.render("Enter IP", True, (0, 0, 0)), (cell_coords[cells.index(cell)][0], cell_coords[cells.index(cell)][1] + font.get_linesize())), (font.render(
"_ _ _._ _ _._ _ _._ _ _", True, (0, 0, 0)), (cell_coords[cells.index(cell)][0], cell_coords[cells.index(cell)][1] + 2 * font.get_linesize() + 2)),
(font.render(typing[cell], True, (0, 0, 0)), (cell_coords[cells.index(cell)][0], cell_coords[cells.index(cell)][1] + 2 * font.get_linesize()))))
if cell_name != "Keyboard":
screen.blit(controller_typing, (cell_coords[cells.index(
cell)][0] + 25, cell_coords[cells.index(cell)][1] + 4 * font.get_linesize()))
else:
bots.get(cell)
for i in range(len(cells), 8):
k = "or press Enter/Return on your keyboard" if 'k' not in cells else ""
screen.blits(((small_font.render("Connect another controller", True, (0, 0, 0)), cell_coords[i]), (small_font.render(
k, True, (0, 0, 0)), (cell_coords[i][0], cell_coords[i][1] + small_font.get_linesize()))))
pygame.display.flip()
for c in joysticks.values(): # type: ignore
c.quit()
pygame.joystick.quit()
pygame.quit() |
I removed the event-polling |
Thanks, I am able to repro the issue with the code you provided. Might need to transfer to pyright repo. |
Please try switching to the pylance insiders release. I'm pretty sure this crash is explained by a bug that I introduced in pyright 1.1.315 and later fixed in pyright 1.1.316. @debonte, if you think it's worth cherry picking the fix to publish a hot fix for the pylance production release, it involves two commits: c8a25b2d6141a23907e3c6c0f188ec45122ec421 and 1340dfac2239b9bb086780bfdb20dee9bd791367. |
Those commits are included in the latest Pylance pre-release build -- 2023.6.41. This issue is only impacting ~30 users at the moment, so hotfixing stable to include the fix seems unnecessary. @xboxone08, can you upgrade to 2023.6.41 and see if the issue is fixed? |
Yes the error is fixed 👍 |
Type: Bug
After deleting the first line in both the release and pre-release versions, Pylance underlines the new first word of the file when Type Checking is set to 'basic' and says:
This error did not occur until yesterday. It has been accompanied with a tremendous slowdown in getting function/method/class annotations and autocomplete. I am on VS Code Insiders if that has anything to do with it. VS Code Insiders gets daily updates, so that could have screwed something up, and Pylance got an update when I had it in pre-release, but the problem, as I mentioned, stayed when I switched to release (yes, I refreshed VS Code when prompted), so I just switched back to pre-release.
Extension version: 2023.6.31
VS Code version: Code - Insiders 1.80.0-insider (da7f05a70eb760e4ce1fe230ae158ae214433341, 2023-06-27T15:13:35.848Z)
OS version: Windows_NT x64 10.0.22621
Modes:
The text was updated successfully, but these errors were encountered: