Skip to content

gh-156515: Correctly filter conditional annotations in FORWARDREF and STRING formats - #156516

Open
JelleZijlstra wants to merge 1 commit into
python:mainfrom
JelleZijlstra:condanno
Open

gh-156515: Correctly filter conditional annotations in FORWARDREF and STRING formats#156516
JelleZijlstra wants to merge 1 commit into
python:mainfrom
JelleZijlstra:condanno

Conversation

@JelleZijlstra

@JelleZijlstra JelleZijlstra commented Aug 28, 2026

Copy link
Copy Markdown
Member

@DavidCEllis

Copy link
Copy Markdown
Contributor

This seems to do the right thing.

Testing-wise I don't think the Format.FORWARDREF case you have is doing anything? In both the VALUE and FORWARDREF cases it's going through _get_dunder_annotations which will succeed.

If you want a FORWARDREF case that fails on main this should work:

class ConditionalForwardRef:
    a: object.undefined
    if False:
        b: str

get_annotations(ConditionalForwardRef, format=Format.FORWARDREF)

I think a case with a: undefined would test a different branch, although that already succeeds on main.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants