Python 3.12(23.10.02) 오류 메시지 개선

2023. 12. 30. 13:12개발 문서/Python

728x90
반응형

변경사항

1. 향상된 오류 메시지

1.1

>>> sys.version_info
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'sys' is not defined. Did you forget to import 'sys'?

- NameError이제 표준 라이브러리의 모듈은 a가 최상위 레벨로 올라갈 때 인터프리터가 표시하는 오류 메시지의 일부로 잠재적으로 제안됩니다 .

1.2

class A:
   def __init__(self):
       self.blech = 1

   def foo(self):
       somethin = blech

>>> A().foo()
Traceback (most recent call last):
  File "<stdin>", line 1
    somethin = blech
               ^^^^^
NameError: name 'blech' is not defined. Did you mean: 'self.blech'?

- 인스턴스 예외 에 대한 오류 제안을 개선합니다

- 이제 NameError메서드에서 a 가 발생하고 인스턴스에 예외의 이름과 정확히 동일한 속성이 있는 경우 self.메서드 범위에서 가장 가까운 일치 항목 대신 제안이 포함됩니다.

1.3

>>> import a.y.z from b.y.z
Traceback (most recent call last):
  File "<stdin>", line 1
    import a.y.z from b.y.z
    ^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: Did you mean to use 'from ... import ...' instead?

- SyntaxError 오류 메시지 개선

- import x from y # 정상

- import y from x # 오류

1.4

>>> from collections import chainmap
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name 'chainmap' from 'collections'. Did you mean: 'ChainMap'?

- ImportError 오류 메시지 개선

# 출처 : https://docs.python.org/ko/3/whatsnew/3.12.html