2

The expression

random.randint(1, 10) == 5

causes my linter to report the error 'Operator "==" not supported for types "int" and "Literal[0]'.

If I try to cast the comparison to an int/int one, like

random.randint(1, 10) == int(5)

It reports "Expected 0 positional arguments" for the int constructor. I figured that it must want me to explicitly label all the keyword arguments, so I tried

random.randint(1, 10) == int(x=5)

and then it reports the baffling trilogy of errors

  • Operator "==" not supported for types "int" and "int" (surely comparing two integers is one of the most absolutely fundamental legitimate operations in any language?)
  • Using deprecated argument x of method int() (the official docs say nothing about this being deprecated)
  • Expected no arguments to int constructor .

How does it expect me to compare two ints, then? I can't find any mention of this anywhere in the docs for Python's type hinting, Pylance, the int constructor, or anything.

GreenTriangle
  • 2,382
  • 2
  • 21
  • 35
  • @aaron Pylance v2023.1.10 in VS Code 1.73.1 using Python 3.11.0. – GreenTriangle Jan 27 '23 at 18:18
  • I couldn't reproduce it with Pylance v2023.1.10 (VS Code and Python versions are irrelevant if your error is from Pylance). Can you share your User and Workspace settings.json files (particularly the keys that start with "`python.analysis.`")? – aaron Jan 29 '23 at 05:14

0 Answers0