Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[ty] Infer bool for not applied to dynamic values#25445

Merged
charliermarsh merged 1 commit into
mainfrom
charlie/fix-ty-3572-unary-not-any
May 29, 2026
Merged

[ty] Infer bool for not applied to dynamic values#25445
charliermarsh merged 1 commit into
mainfrom
charlie/fix-ty-3572-unary-not-any

Conversation

@charliermarsh

Copy link
Copy Markdown
Member

Summary

Prior to this change, we treated all unary operations applied to a dynamic value as producing the same dynamic type. This is appropriate for +, -, and ~, whose dunder implementations may return arbitrary values, but not for not: Python always produces a bool after evaluating its operand's truthiness.

from typing import Any, reveal_type

def check(value: Any) -> None:
    result = reveal_type(not value)  # bool
    result.nonexistent()  # error: `bool` has no attribute `nonexistent`

We now allow not on dynamic operands to use the existing truthiness-inference path, while retaining dynamic propagation for the other unary operators. This restores downstream checking of the resulting boolean value.

Closes astral-sh/ty#3572.

@astral-sh-bot astral-sh-bot Bot added the ty Multi-file analysis & type inference label May 29, 2026
@charliermarsh charliermarsh added the bug Something isn't working label May 29, 2026
@astral-sh-bot

astral-sh-bot Bot commented May 29, 2026

Copy link
Copy Markdown

Typing conformance results

No changes detected ✅

Current numbers
The percentage of diagnostics emitted that were expected errors held steady at 91.94%. The percentage of expected errors that received a diagnostic held steady at 87.09%. The number of fully passing files held steady at 92/134.

@astral-sh-bot

astral-sh-bot Bot commented May 29, 2026

Copy link
Copy Markdown

Memory usage report

Summary

Project Old New Diff Outcome
prefect 722.18MB 722.28MB +0.01% (105.09kB)
sphinx 267.47MB 267.51MB +0.02% (42.18kB)
trio 113.79MB 113.80MB +0.01% (8.66kB)
flake8 46.81MB 46.81MB +0.00% (384.00B)

Significant changes

Click to expand detailed breakdown

prefect

Name Old New Diff Outcome
infer_expression_types_impl 60.30MB 60.39MB +0.15% (92.89kB)
infer_definition_types 89.74MB 89.75MB +0.01% (5.64kB)
infer_expression_type_impl 8.22MB 8.23MB +0.06% (4.72kB)
all_negative_narrowing_constraints_for_expression 6.62MB 6.62MB +0.02% (1.23kB)
all_narrowing_constraints_for_expression 6.79MB 6.79MB +0.02% (1.23kB)
StaticClassLiteral<'db>::try_mro_ 5.34MB 5.34MB -0.02% (1.19kB)
Type<'db>::member_lookup_with_policy_ 17.13MB 17.13MB +0.01% (1.05kB)
loop_header_reachability 469.60kB 470.64kB +0.22% (1.04kB)
StaticClassLiteral<'db>::implicit_attribute_inner_ 7.02MB 7.02MB +0.01% (656.00B)
Specialization 2.63MB 2.63MB -0.02% (512.00B)
is_redundant_with_impl::interned_arguments 2.36MB 2.36MB -0.02% (440.00B)
UnionType 1.32MB 1.32MB -0.03% (352.00B)
GenericAlias 1.13MB 1.12MB -0.02% (288.00B)
StaticClassLiteral<'db>::try_mro_::interned_arguments 1.26MB 1.25MB -0.02% (288.00B)
is_redundant_with_impl 2.16MB 2.16MB -0.01% (240.00B)
... 7 more

sphinx

Name Old New Diff Outcome
infer_expression_types_impl 21.94MB 21.98MB +0.17% (39.32kB)
infer_definition_types 23.94MB 23.94MB +0.00% (1.12kB)
is_redundant_with_impl::interned_arguments 1.16MB 1.16MB -0.04% (528.00B)
UnionType 647.42kB 647.92kB +0.08% (512.00B)
Type<'db>::member_lookup_with_policy_ 7.28MB 7.28MB +0.01% (496.00B)
Type<'db>::class_member_with_policy_ 7.94MB 7.94MB +0.00% (328.00B)
StaticClassLiteral<'db>::implicit_attribute_inner_ 2.39MB 2.39MB +0.01% (296.00B)
StaticClassLiteral<'db>::implicit_attribute_inner_::interned_arguments 1.95MB 1.95MB +0.01% (192.00B)
infer_scope_types_impl 13.47MB 13.47MB +0.00% (180.00B)
Type<'db>::member_lookup_with_policy_::interned_arguments 2.73MB 2.73MB +0.00% (104.00B)
Type<'db>::class_member_with_policy_::interned_arguments 4.21MB 4.21MB +0.00% (104.00B)
all_negative_narrowing_constraints_for_expression 2.54MB 2.54MB +0.00% (84.00B)
all_narrowing_constraints_for_expression 2.60MB 2.60MB +0.00% (84.00B)
loop_header_reachability 373.48kB 373.43kB -0.01% (48.00B)
infer_expression_type_impl 3.01MB 3.01MB -0.00% (36.00B)
... 1 more

trio

Name Old New Diff Outcome
infer_expression_types_impl 6.74MB 6.75MB +0.13% (8.92kB)
infer_expression_type_impl 1.36MB 1.36MB -0.02% (228.00B)
is_redundant_with_impl::interned_arguments 221.98kB 222.15kB +0.08% (176.00B)
infer_scope_types_impl 4.14MB 4.14MB -0.00% (120.00B)
is_redundant_with_impl 194.86kB 194.95kB +0.05% (96.00B)
infer_definition_types 7.69MB 7.69MB +0.00% (72.00B)
Type<'db>::member_lookup_with_policy_ 1.93MB 1.93MB -0.00% (72.00B)
all_negative_narrowing_constraints_for_expression 591.81kB 591.75kB -0.01% (60.00B)
infer_unpack_types 173.45kB 173.39kB -0.03% (60.00B)
all_narrowing_constraints_for_expression 612.71kB 612.65kB -0.01% (60.00B)
StaticClassLiteral<'db>::implicit_attribute_inner_ 738.74kB 738.73kB -0.00% (12.00B)

flake8

Name Old New Diff Outcome
infer_expression_types_impl 1.09MB 1.09MB +0.09% (1.01kB)
is_redundant_with_impl::interned_arguments 91.95kB 91.78kB -0.19% (176.00B)
StaticClassLiteral<'db>::implicit_attribute_inner_ 311.75kB 311.61kB -0.05% (144.00B)
UnionType 68.27kB 68.16kB -0.16% (112.00B)
is_redundant_with_impl 87.29kB 87.20kB -0.11% (96.00B)
infer_scope_types_impl 871.64kB 871.58kB -0.01% (60.00B)
Type<'db>::member_lookup_with_policy_ 573.92kB 573.86kB -0.01% (60.00B)

@astral-sh-bot

astral-sh-bot Bot commented May 29, 2026

Copy link
Copy Markdown

ecosystem-analyzer results

Lint rule Added Removed Changed
invalid-assignment 0 0 1
Total 0 0 1

Raw diff:

sympy (https://github.com/sympy/sympy)
- sympy/printing/pretty/pretty.py:662:9 error[invalid-assignment] Object of type `Unknown | Literal[0]` is not assignable to attribute `baseline` on type `str | prettyForm`
+ sympy/printing/pretty/pretty.py:662:9 error[invalid-assignment] Object of type `int | Unknown` is not assignable to attribute `baseline` on type `str | prettyForm`

Full report with detailed diff (timing results)

@charliermarsh charliermarsh marked this pull request as ready for review May 29, 2026 07:11
@astral-sh-bot astral-sh-bot Bot requested a review from oconnor663 May 29, 2026 07:11
@charliermarsh charliermarsh merged commit 47d742f into main May 29, 2026
60 checks passed
@charliermarsh charliermarsh deleted the charlie/fix-ty-3572-unary-not-any branch May 29, 2026 07:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Any inferred for not x where x: Any

2 participants