You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This definitely is because of deferred annotations. I'm not sure what to do here. The fact is there is code that has not been run. But also, it is likely never to be run, and it's fine that it isn't run.
But it can have errors. This will be an error if you run it in 3.13:
classX:
x: inttttty=1
% python3.13 att.py
Traceback (most recent call last):
File "/Users/ned/coverage/trunk/att.py", line 1, in <module>
class X:
x: inttttt
y = 1
File "/Users/ned/coverage/trunk/att.py", line 2, in X
x: inttttt
^^^^^^^
NameError: name 'inttttt' is not defined
In 3.14, it won't error, but it will if you try to get the annotation:
% python3.14 att.py
Traceback (most recent call last):
File "/Users/ned/coverage/trunk/att.py", line 7, in <module>
get_annotations(X, format=Format.VALUE)
~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/pyenv/pyenv/versions/3.14.0a3/lib/python3.14/annotationlib.py", line 707, in get_annotations
ann = _get_dunder_annotations(obj)
File "/usr/local/pyenv/pyenv/versions/3.14.0a3/lib/python3.14/annotationlib.py", line 842, in _get_dunder_annotations
ann = _BASE_GET_ANNOTATIONS(obj)
File "/Users/ned/coverage/trunk/att.py", line 2, in __annotate__
x: inttttt
^^^^^^^
NameError: name 'inttttt' is not defined
As a user, my feeling is that if the field annotation is considered covered in 3.13 with from __future__ import annotations, then it should also be considered covered under 3.14 without the import.
Here is a naive suggestion. I assume there is a line somewhere to the effect of:
All of the annotations are put into code objects called __annotate__, so I can ignore those when looking for executable lines, and the problem is fixed in commit 2d04835.
Activity
nedbat commentedon Dec 22, 2024
This definitely is because of deferred annotations. I'm not sure what to do here. The fact is there is code that has not been run. But also, it is likely never to be run, and it's fine that it isn't run.
But it can have errors. This will be an error if you run it in 3.13:
In 3.14, it won't error, but it will if you try to get the annotation:
wip: tests for bug #1908, but not sure what to do about it
nedbat commentedon Dec 22, 2024
btw, I also opened a discussion thread about this: https://discuss.python.org/t/how-should-coverage-py-treat-deferred-annotations/74990
fix: ignore deferred annotation code. #1908
nickdrozd commentedon Dec 22, 2024
As a user, my feeling is that if the field annotation is considered covered in 3.13 with
from __future__ import annotations, then it should also be considered covered under 3.14 without the import.Here is a naive suggestion. I assume there is a line somewhere to the effect of:
Maybe that could be changed to:
[-]3.14 field annoation not covered[/-][+]3.14 field annotation not covered[/+]nedbat commentedon Dec 22, 2024
All of the annotations are put into code objects called
__annotate__, so I can ignore those when looking for executable lines, and the problem is fixed in commit 2d04835.nickdrozd commentedon Dec 22, 2024
Tested; works. Thanks!
nedbat commentedon Dec 26, 2024
This is now released as part of coverage 7.6.10.