Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type annotations for functions are absent #3048

Closed
arihant2math opened this issue Mar 15, 2023 · 4 comments
Closed

Type annotations for functions are absent #3048

arihant2math opened this issue Mar 15, 2023 · 4 comments

Comments

@arihant2math
Copy link

Bug Description

There aren't type annotation when using inspect.signature for everything but Options, which produce a Ellipsis as default argument.

Steps to Reproduce

# main.py
import inspect
import test
print(inspect.signature(test.foo))
// lib/src.rs
...
#[pyfunction]
fn foo(a: i64, b: Option<i64>) -> String {
}
...

running the python code would produce:
(a, b=Ellipsis)

Backtrace

No response

Your operating system and version

Windows

Your Python version (python --version)

3.11.2

Your Rust version (rustc --version)

rustc 1.68.0 (2c8cc3432 2023-03-06)

Your PyO3 version

0.18.1

How did you install python? Did you use a virtualenv?

python.org, a virtualenv with maturin was used

Additional Info

No response

@messense
Copy link
Member

messense commented Mar 16, 2023

I think the default value is intentional at the moment

All default values are currently set to .... I think this is ok because .pyi files often do the same. Maybe for numbers, strings, None and True/False we could render these in a future PR.

See #2784

@messense
Copy link
Member

BTW, type annotations are actually not supported in __text_signature__:

Python 3.11.0 (main, Oct 25 2022, 16:25:24) [Clang 14.0.0 (clang-1400.0.29.102)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> def f(): pass
...
>>> import inspect
>>> inspect.signature(f)
<Signature ()>
>>> f.__text_signature__ = "(a:int, b:bool)"
>>> inspect.signature(f)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/messense/.pyenv/versions/3.11.0/lib/python3.11/inspect.py", line 3272, in signature
    return Signature.from_callable(obj, follow_wrapped=follow_wrapped,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/messense/.pyenv/versions/3.11.0/lib/python3.11/inspect.py", line 3020, in from_callable
    return _signature_from_callable(obj, sigcls=cls,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/messense/.pyenv/versions/3.11.0/lib/python3.11/inspect.py", line 2507, in _signature_from_callable
    return _signature_from_function(sigcls, obj,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/messense/.pyenv/versions/3.11.0/lib/python3.11/inspect.py", line 2342, in _signature_from_function
    return _signature_fromstr(cls, func, s, skip_bound_arg)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/messense/.pyenv/versions/3.11.0/lib/python3.11/inspect.py", line 2272, in _signature_fromstr
    p(name, default)
  File "/Users/messense/.pyenv/versions/3.11.0/lib/python3.11/inspect.py", line 2249, in p
    name = parse_name(name_node)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/messense/.pyenv/versions/3.11.0/lib/python3.11/inspect.py", line 2214, in parse_name
    raise ValueError("Annotations are not currently supported")
ValueError: Annotations are not currently supported
>>>

@messense messense removed the bug label Mar 16, 2023
@messense
Copy link
Member

I think we should close this in favor of #2863?

@arihant2math
Copy link
Author

Yeah I think that's a good idea

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants