Python 3

[CPython] int 내부 구조 - Python 3.12

int의 자료구조는 Python 3.11까지는 PyVarObject의 형태였으나 Python 3.12 부터 PyObject로 변경되었다.이 글은 Python 3.13을 기준으로 제작되었다.PyLongObjectPyLongObject는 int 자료형의 구조체이다.// Include/cpython/longintrepr.h// line 93typedef struct _PyLongValue { uintptr_t lv_tag; /* Number of digits, sign and flags */ digit ob_digit[1];} _PyLongValue;// line 98struct _longobject { PyObject_HEAD _PyLongValue long_value;};_PyLong..

Python 2024.11.12

[Python] typing - Callable

CallableCallable은 Python에서 호출 가능한 객체의 표현 타입이다.객체가 호출 가능한지는 callable 함수를 통해 확인 할 수 있다.# Callable Oprint(callable(print))# Callable Xprint(callable(1))결과TrueFalse __call__객체를 호출하였을 경우 실핼되는 함수는 객체의 magic method인 __call__이다.객체의 call 함수는 객체의 type에 명시되어 있다.print(print.__class__.__dict__["__call__"])결과 CPython의 call과 callableCPython의 type objectstruct _typeobject { PyObject_VAR_HEAD ... ternar..

Python 2024.11.05