from typing import List - 형 힌트 지원

typing 모듈

문제 상황

리트 코드에서 푼 문제를 VSCode에 옮겨 놓으니

1
def maxSubArray(self, nums: ***List***[int]) -> int:

타입 힌트를 주는 List에 밑줄이 생기며 아래와 같은 오류 메세지가 나왔다.

“List” is not defined


문제 해결

1
from typing import List

를 import 해줌으로써 해결했다.


문제 원인

리트 코드에서는

1
from typing import *

를 기본적으로 import 처리해두기 때문에 별도로 import하지 않고 사용했지만,
VSCode에서는 별도로 imort가 필요했던 것이다.


그 외 리트코드에서 기본적으로 import 처리해 둔 모듈

  • import collections
  • import heapq
  • import functools
  • import itertools
  • import re
  • import sys
  • import math
  • import bisect
  • from typing import *

참고 문서

https://docs.python.org/3/library/typing.html
https://www.python.org/dev/peps/pep-0484/