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

function parameter of type Literal[-1] gives incorrect error #260

Closed
judej opened this issue Aug 20, 2020 · 2 comments
Closed

function parameter of type Literal[-1] gives incorrect error #260

judej opened this issue Aug 20, 2020 · 2 comments
Labels
bug Something isn't working fixed in next version (main) A fix has been implemented and will appear in an upcoming version

Comments

@judej
Copy link
Contributor

judej commented Aug 20, 2020

Environment data

Pylance language server 2020.8.1 (pyright 0916fb9e)

def foo(neg1: Literal[-1]) -> None:
    pass

def bar(pos1: Literal[1]) -> None:
    pass

# the following results in error:
#     "int" cannot be assigned to type "Literal[-1]"Pylance 
foo(-1)

# this is ok
bar(1)

Expected behaviour

No error for foo(-1) above

Actual behaviour

"int" cannot be assigned to type "Literal[-1]"Pylance

@erictraut
Copy link
Contributor

Thanks for the bug report. The type evaluator wasn't properly evaluating the type of expressions with unary +/- operators and integer literal operands. These should result in a literal type, but the literal value was being omitted when the unary expression was applied. I've fixed it in a way that +/- operations can be applied in a chained manner (e.g. "-(-++(-3))" evaluates to the type "Literal[-3]".

@erictraut erictraut added bug Something isn't working fixed in next version (main) A fix has been implemented and will appear in an upcoming version labels Aug 20, 2020
@jakebailey
Copy link
Member

This issue has been fixed in version 2020.8.2, which we've just released. You can find the changelog here: https://github.com/microsoft/pylance-release/blob/master/CHANGELOG.md#202082-20-august-2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed in next version (main) A fix has been implemented and will appear in an upcoming version
Projects
None yet
Development

No branches or pull requests

3 participants