Skip to content

[ty] Add NewTypes to the property tests#24113

Merged
AlexWaygood merged 1 commit intomainfrom
claude/add-newtype-property-tests-qvtcK
Mar 23, 2026
Merged

[ty] Add NewTypes to the property tests#24113
AlexWaygood merged 1 commit intomainfrom
claude/add-newtype-property-tests-qvtcK

Conversation

@AlexWaygood
Copy link
Copy Markdown
Member

Summary

This should give us more confidence when refactoring NewType-related code in relation.rs

Test Plan

I ran QUICKCHECK_TESTS=1000000 cargo test --profile=profiling -p ty_python_semantic -- --ignored types::property_tests::stable and didn't observe any failures

@AlexWaygood AlexWaygood added the testing Related to testing Ruff itself label Mar 22, 2026
@AlexWaygood AlexWaygood added the ty Multi-file analysis & type inference label Mar 22, 2026
@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot bot commented Mar 22, 2026

Typing conformance results

No changes detected ✅

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

@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot bot commented Mar 22, 2026

Memory usage report

Memory usage unchanged ✅

@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot bot commented Mar 22, 2026

ecosystem-analyzer results

Lint rule Added Removed Changed
invalid-await 0 40 0
invalid-return-type 0 1 0
Total 0 41 0

Changes in flaky projects detected. Raw diff output excludes flaky projects; see the HTML report for details.

Full report with detailed diff (timing results)

@AlexWaygood AlexWaygood force-pushed the claude/add-newtype-property-tests-qvtcK branch from 20f2deb to e32d96b Compare March 22, 2026 22:05
Copy link
Copy Markdown
Contributor

@sharkdp sharkdp left a comment

Choose a reason for hiding this comment

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

Thank you!

Comment on lines +10 to +25
let db = CACHED_DB.get_or_init(|| {
let db = TestDbBuilder::new()
.with_file(
NEWTYPE_MODULE_PATH,
"\
from typing import NewType

NewTypeOfInt = NewType('NewTypeOfInt', int)
NewTypeOfFloat = NewType('NewTypeOfFloat', float)
NewTypeOfComplex = NewType('NewTypeOfComplex', complex)
NewTypeOfStr = NewType('NewTypeOfStr', str)",
)
.build()
.unwrap();
Arc::new(Mutex::new(db))
});
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.

Ah, nice. I should have done that for other examples as well. That will also be useful for things like TypedDicts. I think we could maybe consider making that setup more general (in the sense that we could rename that module to just type_candidates.py or similar), or do you see any advantage from having multiple files (one for newtype candidates, one for typeddict candidates, …)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, making it a consolidated source file makes sense! I'll rename it.

That will also be useful for things like TypedDicts.

Yes -- though for TypedDicts, we can also use a similar strategy to what we use for Callables, since (unlike NewTypes) we're able to create synthesized TypedDicts with no source definition. An advantage of using synthesized TypedDicts would be increased randomness; a disadvantage would be... increased randomness. (If we have the property tests select from fixed TypedDicts in a source file, we know it's more likely to pick an "interesting" TypedDict when it does pick a TypedDict). Possibly a combination of the two strategies might work well for TypedDicts and Protocols?

@AlexWaygood AlexWaygood force-pushed the claude/add-newtype-property-tests-qvtcK branch from e32d96b to 74a08a1 Compare March 23, 2026 12:18
@AlexWaygood AlexWaygood enabled auto-merge (squash) March 23, 2026 12:18
@AlexWaygood AlexWaygood merged commit 0069748 into main Mar 23, 2026
48 checks passed
@AlexWaygood AlexWaygood deleted the claude/add-newtype-property-tests-qvtcK branch March 23, 2026 12:22
carljm added a commit that referenced this pull request Mar 25, 2026
* main: (36 commits)
  [ty] Reduce diagnostic range for `invalid-metaclass` (#24145)
  [ty] Simplify TypeVar assignability/subtyping logic (#24138)
  [ty] Prevent tainted loop bindings in cycle normalization (#24143)
  [ty] Add precisely-typed overloads for `TypedDict` update (#24101)
  [ty] Fix folding ranges of comments separated by statements (#24132)
  Bump ecosystem-analyzer pin (#24136)
  Bump ecosystem-analyzer pin (#24135)
  Simplify `NewType` handling in `relation.rs` (#24109)
  [ty] Add more tests for `NewType` subtyping (#24115)
  [ty] Add `NewType`s to the property tests (#24113)
  [ty] Prepare test files for unreachable code change (#24133)
  `analyze graph`: resolve string imports that reference attributes, not just modules (#24058)
  Update Artifact GitHub Actions dependencies (#24116)
  Update taiki-e/install-action action to v2.68.33 (#24130)
  Update taiki-e/install-action action to v2.68.32 (#24123)
  Update Rust crate serde_with to v3.18.0 (#24126)
  Update Swatinem/rust-cache action to v2.9.1 (#24127)
  Update Rust crate quick-junit to 0.6.0 (#24125)
  Update Rust crate clap to v4.6.0 (#24124)
  Update Rust crate tracing-subscriber to v0.3.23 (#24122)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

testing Related to testing Ruff itself ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants