파이썬 지연 평가 어노테이션

Python deferred annotations

Python 3.14는 어노테이션 표현식의 평가를 조회 시점까지 미룹니다.

···
html
<div class="visual deferred" data-step="0"><div class="visual-head"><strong>DEFERRED ANNOTATION</strong><i></i></div><div class="visual-scene"><div class="defer-line"></div><div class="defer-events"><span>define</span><span>hold expr</span><span>define name</span><span>inspect</span></div><div class="defer-hand"></div></div><div class="visual-caption"></div><div class="visual-dots"><b></b><b></b><b></b><b></b></div></div>
css
.visual{width:min(95vw,760px);height:min(91vh,330px);padding:clamp(9px,2.5vmin,18px);display:flex;flex-direction:column;gap:clamp(6px,1.7vmin,11px);border:1px solid var(--line);border-radius:13px;background:var(--surface);font:500 clamp(12px,3.4vmin,16px)/1.25 var(--font-sans,-apple-system),sans-serif}
.visual-head{display:flex;align-items:center;justify-content:space-between;gap:8px;min-height:19px;color:var(--accent)}.visual-head strong{font-size:1em}.visual-head i{display:block;width:8px;height:8px;flex:none;border-radius:50%;background:var(--accent);animation:visual-pulse 1.3s infinite}@keyframes visual-pulse{50%{opacity:.25}}
.visual-scene{position:relative;flex:1;min-height:0;overflow:hidden}.visual-caption{min-height:2.4em;display:grid;place-items:center;text-align:center}.visual-dots{display:flex;justify-content:center;gap:4px}.visual-dots b{display:block;width:15px;height:3px;border-radius:3px;background:var(--line)}.visual-dots b.on{background:var(--accent)}
.visual-scene *{box-sizing:border-box}.visual-scene .mono{font-family:ui-monospace,monospace}.visual-scene .muted{color:var(--muted)}.visual-scene .lit{border-color:var(--accent)!important;background:color-mix(in srgb,var(--accent) 14%,var(--surface))!important;color:var(--fg)!important}
.deferred .visual-scene{display:flex;align-items:center;justify-content:center}.defer-line{position:absolute;left:7%;right:7%;top:max(8px,calc(50% - 47px));height:3px;background:var(--line)}.defer-events{display:flex;width:100%;justify-content:space-between;position:relative;padding-top:16px}.defer-events span{width:22%;height:55px;border:1px solid var(--line);border-radius:7px;background:var(--bg);display:grid;place-items:center;text-align:center;transition:background .3s}.defer-hand{position:absolute;top:max(1px,calc(50% - 54px));left:9%;width:16px;height:16px;background:var(--accent);border-radius:50%;transition:left .45s}.deferred[data-step="1"] .defer-hand{left:34%}.deferred[data-step="2"] .defer-hand{left:60%}.deferred[data-step="3"] .defer-hand{left:86%}.deferred[data-step="0"] .defer-events span:first-child,.deferred[data-step="1"] .defer-events span:nth-child(2),.deferred[data-step="2"] .defer-events span:nth-child(3),.deferred[data-step="3"] .defer-events span:last-child{border-color:var(--accent);background:color-mix(in srgb,var(--accent) 14%,var(--surface))}
js
const root=document.querySelector('.visual'),cap=root.querySelector('.visual-caption'),dots=[...root.querySelectorAll('.visual-dots b')],captions=["Define without resolving","Keep the expression","Name becomes available","Evaluate on inspection"];let step=0;function advance(){root.dataset.step=String(step);cap.textContent=captions[step];dots.forEach((d,i)=>d.classList.toggle('on',i===step));if(root.classList.contains('generic')){root.querySelector('.generic-input').textContent=step===3?'"hi"':'7';root.querySelector('.generic-output').textContent=step===3?'"hi" : string':'7 : number'}if(root.classList.contains('union'))root.querySelector('.set-value').textContent=step%2?'value: "seven"':'value: 7';step=(step+1)%captions.length}advance();let timer=setInterval(advance,1100);root.addEventListener('pointerdown',()=>{clearInterval(timer);advance()})

Python 3.14의 어노테이션은 함수나 클래스를 정의할 때 곧바로 평가하지 않습니다. 이름 참조가 나중에 정의되어도 어노테이션 조회 시점에 해석할 수 있습니다.

데모는 정의·보관·조회 단계를 차례로 강조합니다. 어노테이션을 직접 읽는 프레임워크는 평가 형식과 실패 시점을 확인해야 합니다.

언제 쓰나

상호 참조 타입을 선언하거나 런타임에 어노테이션을 읽는 라이브러리를 다룰 때 이해해야 합니다.

페이지로 열기 ↗