Suppress NameError for undefined names in annotations#3
Conversation
| def test_annotation_name(self): | ||
| an = types.AnnotationName("x") | ||
| self.assertEqual(repr(an), "<unresolved name: x>") | ||
| # TODO for some reason __name__ doesn't exist if I don't do this first |
There was a problem hiding this comment.
This is really weird to me: somehow .__name__ only exists on AnnotationName objects after I've done something like AnnotationName.__dict__. My implementation mostly followed that of GenericAlias, which doesn't have this problem. I'll stare at it some more, but maybe someone who knows more about CPython internals will know the reason.
|
|
||
| AnnotationName = type(f.__annotations__["x"]) | ||
| del f | ||
|
|
There was a problem hiding this comment.
This could be moved up to use the function _f() on line 12. Then both types could be extracted from one function instead of two.
|
I appreciate you writing this PR, but unfortunately I don't like this. My goal in designing PEP 649 was to take stock semantics and time-shift the evaluation of the annotations, adding as little opinion as possible. I think catching If I'm reading it correctly, this PR would suppress Also, as currently implemented it doesn't permit getting attributes or indexing into the Also, the PR only adds I've mentioned this idea in PEP 649, so I assume the Steering Committee is aware of it. If they accept PEP 649 but stipulate that it must implement this or similar functionality, naturally I will revisit your PR then. Again, thank you for proposing this; it's certainly not my goal to belittle your proposal. I appreciate your efforts to improve PEP 649. |
|
Thanks, and no worries! It's certainly a more ambitious change to semantics than PEP 649 as it stands. The problems you bring up (missing opcodes, missing subscript functionality) can be fixed, but as you say they would make the change even more involved. Let's close this for now and revisit it if the SC turns out to be interested in this approach. |
A possible proof-of-concept fix for #1. I'm sure there's some subtlety I missed.