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

Import Issue: "NameError: name 'StrictNvimApi' is not defined" #1

Closed
erutan2099 opened this issue Apr 1, 2023 · 1 comment
Closed

Comments

@erutan2099
Copy link

erutan2099 commented Apr 1, 2023

I am trying to import ribosome in python and I keep encountering this error:

'''js
"
{

import ribosome
Traceback (most recent call last):
File "", line 1, in
File "C:\Program Files\Python310\lib\site-packages\ribosome_init_.py", line 6, in
from ribosome.nvim.api.data import NvimApi
File "C:\Program Files\Python310\lib\site-packages\ribosome\nvim\api\data.py", line 31, in
class StrictNvimApi(NvimApi):
File "C:\Program Files\Python310\lib\site-packages\amino\dat.py", line 107, in new
fs = Map(namespace).lift('init') / (lambda a: init_fields(a, globalns)) | Nil
File "C:\Program Files\Python310\lib\site-packages\amino\tc\base.py", line 244, in wrap
return f(self, *a, **kw) # type: ignore
File "C:\Program Files\Python310\lib\site-packages\amino\tc\functor.py", line 23, in truediv
return self.map(fa, f)
File "C:\Program Files\Python310\lib\site-packages\amino\tc\monad.py", line 15, in map
return self.flat_map(fa, lambda a: self.pure(f(a)))
File "C:\Program Files\Python310\lib\site-packages\amino\instances\maybe.py", line 43, in flat_map
return fa.cata(lambda v: f(v), Nothing)
File "C:\Program Files\Python310\lib\site-packages\amino\maybe.py", line 54, in cata
f(cast(A, self._get))
File "C:\Program Files\Python310\lib\site-packages\amino\instances\maybe.py", line 43, in
return fa.cata(lambda v: f(v), Nothing)
File "C:\Program Files\Python310\lib\site-packages\amino\tc\monad.py", line 15, in
return self.flat_map(fa, lambda a: self.pure(f(a)))
File "C:\Program Files\Python310\lib\site-packages\amino\dat.py", line 107, in
fs = Map(namespace).lift('init') / (lambda a: init_fields(a, globalns)) | Nil
File "C:\Program Files\Python310\lib\site-packages\amino\dat.py", line 94, in init_fields
types = Map(get_type_hints(init))
File "C:\Program Files\Python310\lib\typing.py", line 1849, in get_type_hints
value = _eval_type(value, globalns, localns)
File "C:\Program Files\Python310\lib\typing.py", line 326, in _eval_type
return t._evaluate(globalns, localns, recursive_guard)
File "C:\Program Files\Python310\lib\typing.py", line 696, in _evaluate
self.forward_value = _eval_type(
File "C:\Program Files\Python310\lib\typing.py", line 328, in _eval_type
ev_args = tuple(_eval_type(a, globalns, localns, recursive_guard) for a in t.args)
File "C:\Program Files\Python310\lib\typing.py", line 328, in
ev_args = tuple(_eval_type(a, globalns, localns, recursive_guard) for a in t.args)
File "C:\Program Files\Python310\lib\typing.py", line 326, in _eval_type
return t._evaluate(globalns, localns, recursive_guard)
File "C:\Program Files\Python310\lib\typing.py", line 691, in _evaluate
eval(self.forward_code, globalns, localns),
File "", line 1, in
NameError: name 'StrictNvimApi' is not defined

}
"
'''

Any help for resolving this would be appreciated.

@erutan2099
Copy link
Author

Update: after digging, I found a workaround:

in nvm.api.data.py, I edited the code to appear like this:

...

...

def no_request_handler(vim: 'StrictNvimApi', method: str, args: List[Any], sync: bool ) -> Either[List[str], Tuple[NvimApi, Any]]: return Left(List('no request handler defined'))

class StrictNvimApi(NvimApi): @staticmethod def cons( name: str, vars: Map[str, Any]=Map(), request_handler: StrictNvimHandler=no_request_handler, request_log: List[Tuple[str, List[Any]]]=Nil, ) -> 'StrictNvimApi': return StrictNvimApi(name, vars, request_handler, request_log)

class StrictNvimApi(NvimApi): @staticmethod def cons( name: str, vars: Map[str, Any]=Map(), request_handler: StrictNvimHandler=no_request_handler, request_log: List[Tuple[str, List[Any]]]=Nil, ) -> 'StrictNvimApi': return StrictNvimApi(name, vars, request_handler, request_log) def __init__( self, name: str, vars: Map[str, Any], request_handler: StrictNvimHandler, request_log: List[Tuple[str, List[Any]]], ) -> None: self.name = name self.vars = vars self.request_handler = request_handler self.request_log = request_log def request(self, method: str, args: List[Any], sync: bool, timeout: float) -> Either[str, Tuple[NvimApi, Any]]: vim = self.append1.request_log((method, args)) return self.request_handler(vim, method, args, sync).accum_error_lift(variable_request, vim, method, args) def var(self, name: str) -> Either[str, Any]: return self.vars.lift(name).to_either(f'no variable `{name}` defined')

...

...

which essentially duplicated the first function in the StrictNvimApi class. I am not 100% sure why this works, but it seems to have fixed the issue.

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

1 participant