Skip to content

[ty] Use basic blocks for determining if a node is in an if TYPE_CHECKING block#24394

Merged
AlexWaygood merged 2 commits intomainfrom
alex/type-checking-blocks
Apr 6, 2026
Merged

[ty] Use basic blocks for determining if a node is in an if TYPE_CHECKING block#24394
AlexWaygood merged 2 commits intomainfrom
alex/type-checking-blocks

Conversation

@AlexWaygood
Copy link
Copy Markdown
Member

@AlexWaygood AlexWaygood added the ty Multi-file analysis & type inference label Apr 3, 2026
@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot Bot commented Apr 3, 2026

Typing conformance results

No changes detected ✅

Current numbers
The percentage of diagnostics emitted that were expected errors held steady at 87.72%. The percentage of expected errors that received a diagnostic held steady at 82.85%. The number of fully passing files held steady at 74/132.

@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot Bot commented Apr 3, 2026

Memory usage report

Summary

Project Old New Diff Outcome
prefect 717.91MB 718.34MB +0.06% (438.04kB)
sphinx 264.96MB 265.15MB +0.07% (195.79kB)
trio 117.82MB 117.90MB +0.07% (80.04kB)
flake8 48.02MB 48.05MB +0.07% (34.03kB)

Significant changes

Click to expand detailed breakdown

prefect

Name Old New Diff Outcome
semantic_index 172.14MB 172.57MB +0.25% (445.70kB)
check_file_impl 17.98MB 17.97MB -0.03% (6.32kB)
infer_definition_types 90.07MB 90.07MB -0.00% (500.00B)
Type<'db>::class_member_with_policy_ 17.99MB 17.99MB -0.00% (316.00B)
infer_scope_types_impl 54.29MB 54.29MB -0.00% (212.00B)
Type<'db>::member_lookup_with_policy_ 16.36MB 16.36MB -0.00% (124.00B)
Type<'db>::class_member_with_policy_::interned_arguments 9.73MB 9.73MB -0.00% (104.00B)
Type<'db>::member_lookup_with_policy_::interned_arguments 5.87MB 5.87MB -0.00% (104.00B)

sphinx

Name Old New Diff Outcome
semantic_index 61.01MB 61.20MB +0.31% (194.14kB)
check_file_impl 4.96MB 4.96MB -0.03% (1.52kB)
ClassType<'db>::nearest_disjoint_base_ 65.08kB 65.66kB +0.89% (596.00B)
Type<'db>::member_lookup_with_policy_ 6.54MB 6.54MB +0.01% (556.00B)
infer_expression_types_impl 21.55MB 21.55MB +0.00% (540.00B)
Type<'db>::class_member_with_policy_ 7.70MB 7.70MB +0.00% (232.00B)
infer_definition_types 24.03MB 24.03MB -0.00% (228.00B)
BoundMethodType<'db>::into_callable_type_ 278.27kB 278.46kB +0.07% (192.00B)
IntersectionType<'db>::from_two_elements_ 35.03kB 35.21kB +0.52% (188.00B)
IntersectionType 872.38kB 872.56kB +0.02% (184.00B)
CallableType 1.11MB 1.11MB +0.01% (144.00B)
infer_scope_types_impl 15.50MB 15.50MB +0.00% (136.00B)
TupleType 568.66kB 568.78kB +0.02% (128.00B)
UnionType<'db>::from_two_elements_ 1.38MB 1.38MB +0.01% (116.00B)
Type<'db>::class_member_with_policy_::interned_arguments 4.05MB 4.05MB +0.00% (104.00B)
... 4 more

trio

Name Old New Diff Outcome
semantic_index 29.94MB 30.03MB +0.28% (87.18kB)
check_file_impl 1.82MB 1.81MB -0.25% (4.67kB)
infer_definition_types 7.73MB 7.73MB -0.01% (1.02kB)
Type<'db>::class_member_with_policy_ 2.04MB 2.04MB -0.03% (632.00B)
Type<'db>::member_lookup_with_policy_ 1.83MB 1.83MB -0.02% (312.00B)
Type<'db>::member_lookup_with_policy_::interned_arguments 930.01kB 929.70kB -0.03% (312.00B)
Type<'db>::class_member_with_policy_::interned_arguments 1.12MB 1.12MB -0.02% (208.00B)
infer_scope_types_impl 4.78MB 4.78MB -0.00% (24.00B)

flake8

Name Old New Diff Outcome
semantic_index 13.71MB 13.75MB +0.24% (34.03kB)

@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot Bot commented Apr 3, 2026

ecosystem-analyzer results

Lint rule Added Removed Changed
unsupported-operator 0 5 0
Total 0 5 0

Raw diff:

pydantic (https://github.com/pydantic/pydantic)
- pydantic/_internal/_repr.py:18:42 error[unsupported-operator] Operator `|` is unsupported between objects of type `<class 'str'>` and `None`
- pydantic/_internal/_repr.py:19:42 error[unsupported-operator] Operator `|` is unsupported between objects of type `<special-form 'typing.Any'>` and `<class 'tuple[Any]'>`
- pydantic/_internal/_utils.py:33:35 error[unsupported-operator] Operator `|` is unsupported between objects of type `<class 'Mapping[int, Any]'>` and `<class 'Mapping[str, Any]'>`
- pydantic/_internal/_utils.py:34:36 error[unsupported-operator] Operator `|` is unsupported between objects of type `<class 'AbstractSet[int]'>` and `<class 'AbstractSet[str]'>`

xarray (https://github.com/pydata/xarray)
- xarray/core/dataarray.py:127:52 error[unsupported-operator] Operator `|` is unsupported between objects of type `Literal["DataArray"]` and `<class 'Dataset'>`

Full report with detailed diff (timing results)

@AlexWaygood AlexWaygood force-pushed the alex/type-checking-blocks branch from e6a8ff1 to dec71e2 Compare April 3, 2026 15:01
@AlexWaygood AlexWaygood marked this pull request as ready for review April 3, 2026 15:24
Copy link
Copy Markdown
Contributor

@carljm carljm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

Comment thread crates/ty_python_semantic/src/semantic_index/builder.rs
Comment thread crates/ty_python_semantic/src/semantic_index/use_def.rs Outdated
Comment thread crates/ty_python_semantic/src/semantic_index/use_def.rs Outdated
scope_id: FileScopeId,
range: TextRange,
) -> bool {
self.scope(scope_id).in_type_checking_block()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need to separately track per-scope in_type_checking_block?

Copy link
Copy Markdown
Member Author

@AlexWaygood AlexWaygood Apr 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, we don't -- and we don't need to track per-scope reachability either. I'll revive a version of #24392 after this PR lands and expand it to also get rid of the in_type_checking_block field/method from Scope, as well as the reachability field.

Copy link
Copy Markdown
Contributor

@sharkdp sharkdp Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, we don't -- and we don't need to track per-scope reachability either

Curious to see that! I tried to remove per-scope reachability some weeks ago, and it wasn't (easily) possible, if I remember correctly.

@AlexWaygood AlexWaygood enabled auto-merge (squash) April 6, 2026 20:01
@AlexWaygood AlexWaygood merged commit 770cca6 into main Apr 6, 2026
51 checks passed
@AlexWaygood AlexWaygood deleted the alex/type-checking-blocks branch April 6, 2026 20:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TYPE_CHECKING constraints should apply to basic blocks, not scopes

4 participants