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

Allow inferring +int to be a Literal #16910

Merged
merged 4 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Feb 12, 2024
commit 4157220c77585c15d47a62bd9f47ab61825bc889
2 changes: 1 addition & 1 deletion mypy/exprtotype.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def expr_to_unanalyzed_type(
elif isinstance(expr, UnaryExpr):
typ = expr_to_unanalyzed_type(expr.expr, options, allow_new_syntax)
if isinstance(typ, RawExpressionType):
if isinstance(typ.literal_value, int) :
if isinstance(typ.literal_value, int):
if expr.op == "-":
typ.literal_value *= -1
return typ
Expand Down
5 changes: 4 additions & 1 deletion mypy/plugins/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,10 @@ def int_neg_callback(ctx: MethodContext, multiplier: int = -1) -> Type:
else:
return ctx.type.copy_modified(
last_known_value=LiteralType(
value=multiplier * value, fallback=ctx.type, line=ctx.type.line, column=ctx.type.column
value=multiplier * value,
fallback=ctx.type,
line=ctx.type.line,
column=ctx.type.column,
)
)
elif isinstance(ctx.type, LiteralType):
Expand Down
Loading