Message387875
We have a pytest that boils down to the following:
```
#from __future__ import annotations
from inspect import Parameter, signature
def foo(x: str) -> str:
return x + x
def test_foo():
expected = (
Parameter("x", Parameter.POSITIONAL_OR_KEYWORD, annotation=str),
)
actual = tuple(signature(foo).parameters.values())
assert expected == actual
```
(execute with `pip install pytest && pytest -vv test_foo.py`)
I tried importing 3.10 annotations (so that we can get rid of quotes around the class containing `foo()`, which is omitted here because it isn't necessary to reproduce the bug), but doing so changes the output of `inspect.signature()` but not the output `inspect.Parameter()`, causing a mismatch between the two that breaks the test.
The above passes on 3.7.9, 3.8.7 & 3.9.1, and if I uncomment the first line, it fails on those same versions.
As can be expected, the annotations import is a no-op on 3.10.0a5 and the test passes either way.
I expect `inspect` might have not been correctly updated to support postponed annotations, but I haven't looked at the implementation (I'm not familiar with the CPython codebase at all) so it's just a guess. |
|
Date |
User |
Action |
Args |
2021-03-01 16:02:00 | 1ace | set | recipients:
+ 1ace |
2021-03-01 16:02:00 | 1ace | set | messageid: <1614614520.28.0.353733927276.issue43355@roundup.psfhosted.org> |
2021-03-01 16:02:00 | 1ace | link | issue43355 messages |
2021-03-01 16:01:59 | 1ace | create | |
|