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

'TreeInstance' object has no attribute 'with_generics' when using typing.Literal["str"] return annotation on property #1990

Open
Carreau opened this issue Apr 22, 2024 · 4 comments
Labels

Comments

@Carreau
Copy link
Contributor

Carreau commented Apr 22, 2024

See upstream issue ipython/ipython#14412, that I was able to reduce to

import jedi
import typing


class A:
    @property
    def value(self) -> typing.Literal["a"]:
        return "a"


a = A()

interp = jedi.Interpreter("a.", [{"a": a}])
interp.complete(line=1, column=2)
Traceback (most recent call last):
  File "/.../jtree.py", line 14, in <module>
    interp.complete(line=1, column=2)
  File "/.../jedi/api/helpers.py", line 487, in wrapper
    return func(self, line, column, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/.../jedi/api/__init__.py", line 215, in complete
    return completion.complete()
           ^^^^^^^^^^^^^^^^^^^^^
  File "/.../jedi/api/completion.py", line 170, in complete
    cached_name, completion_names = self._complete_python(leaf)
                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/.../jedi/api/completion.py", line 284, in _complete_python
    cached_name, n = self._complete_trailer(dot.get_previous_leaf())
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/.../jedi/api/completion.py", line 399, in _complete_trailer
    return cached_name, self._complete_trailer_for_values(values)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/.../jedi/api/completion.py", line 404, in _complete_trailer_for_values
    return complete_trailer(user_context, values)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/.../jedi/api/completion.py", line 550, in complete_trailer
    completion_names += filter.values()
                        ^^^^^^^^^^^^^^^
  File "/.../jedi/inference/compiled/value.py", line 494, in values
    names += self._get(
             ^^^^^^^^^^
  File "/.../jedi/inference/compiled/value.py", line 462, in _get
    ).execute_annotation()
      ^^^^^^^^^^^^^^^^^^^^
  File "/.../jedi/inference/compiled/value.py", line 260, in execute_annotation
    return ValueSet([
                    ^
  File "/.../jedi/inference/compiled/value.py", line 261, in <listcomp>
    v.with_generics(arguments)
    ^^^^^^^^^^^^^^^
AttributeError: 'TreeInstance' object has no attribute 'with_generics'
@Carreau Carreau changed the title 'TreeInstance' object has no attribute 'with_generics' when using typing.Literal["str"] annotation. 'TreeInstance' object has no attribute 'with_generics' when using typing.Literal["str"] return annotation on property Apr 22, 2024
@davidhalter
Copy link
Owner

Thanks!

@SarthakNikhal
Copy link

@Carreau @davidhalter Can I help with this issue? Let me know if you have any ideas on fixing it.

@davidhalter
Copy link
Owner

I think Literal needs special casing here. This is definitely something can and should do. We should however probably try to also catch the case where with_generics does not exist on v. (Essentially catch the AttributeError)

@jamespreed
Copy link

This is affecting completion of pandas.Series objects as well.

import pandas as pd
from jedi import Interpreter

series = pd.Series([1,2,3])
code = 'series.'
ns = [{'series': series}]
Interpreter(code, ns).complete()

which raises the same error: AttributeError: 'TreeInstance' object has no attribute 'with_generics'

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

No branches or pull requests

4 participants