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

Fix: evaluate v:true/v:false to python bool type #506

Merged
merged 1 commit into from
May 12, 2022
Merged

Fix: evaluate v:true/v:false to python bool type #506

merged 1 commit into from
May 12, 2022

Conversation

uzxmx
Copy link
Contributor

@uzxmx uzxmx commented May 9, 2022

This PR fixes an issue that when calling vim.eval('v:true'), or vim.eval('v:false'), it gives the wrong str type.

In the latest version of vim, when executing below Ex command, the result is <class 'bool'>. But in neovim, it is <class 'str'>.

:py3 print(type(vim.eval('v:true')))

@wookayin
Copy link
Member

Follow-up: There was a concern raised in #523 (comment) that it doesn't conform with the python-eval doc: https://neovim.io/doc/user/if_pyth.html#python-eval

@justinmk
Copy link
Member

Can you send a PR to update the docs?

@wookayin
Copy link
Member

I think more decisions on the behavior of python-eval would be needed. Same as in the legacy vim, do we want to make the return type as string for numeric/boolean values? What's the main rationale behind any decision?

@uzxmx Do you have any idea why you wanted this change?

@justinmk
Copy link
Member

Reverted in #562

See #523 (comment) :

the #506 PR is not compliant with the vim.eval documentation.

The documentation states

vim.eval(str) python-eval
Evaluates the expression str using the vim internal expression
evaluator (see expression). Returns the expression result as:
(1) a string if the Vim expression evaluates to a string or number
(2) a list if the Vim expression evaluates to a Vim list
(3) a dictionary if the Vim expression evaluates to a Vim dictionary Dictionaries and lists are recursively expanded.

In Python, booleans are implemented as a subclass of integers. In nvim, v:true and v:false evalutes to true and false (boolean values); for boolean values vim uses numbers. Therefore, by (1) and that booleans are integers in Python, vim.eval('v:true') should evaluate to the Python string "True" and not the boolean True. And therefore :py3 print(type(vim.eval('v:true'))) should print out <class 'str'> and not <class 'bool'>. Thus, the extra check in #506 is redundant, right?

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

Successfully merging this pull request may close these issues.

3 participants