GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — build(pyrefly): enable Pyrefly static type checking across Python targets by rickeylev · Pull Request #4020 · bazel-contrib/rules_python

Conversation

@rickeylev

@rickeylev rickeylev commented Aug 8, 2026

Copy link
Copy Markdown
Collaborator

Enables Pyrefly static type checking across Python source and test
targets in rules_python and sphinxdocs.

Previously, static type analysis was not uniformly applied across
all Python targets, leaving potential type inconsistencies and
unbound variable edge cases uncaught during builds and CI runs.

This change configures the global Pyrefly aspect to evaluate Python
targets by default in Bzlmod mode, adds type annotations and
narrowing assertions on runfiles resolution, and annotates dynamic
imports (such as generated protobuf stubs and compiled C extensions)
with explicit type ignore comments. Targets utilizing dynamically
generated bootstrap wrappers retain opt-out tags with documented
rationales.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
rickeylev added 30 commits August 6, 2026 08:05
@rickeylev
Add rules_pyrefly static type checking for //python/runfiles:runfiles
ad6674f
Integrates rules_pyrefly in MODULE.bazel, defines the Pyrefly aspect in tools/pyrefly.bzl with --config=pyrefly in .bazelrc, and addresses a type override suppression in python/runfiles/runfiles.py.
@rickeylev
Move Pyrefly aspect to tools/private/pyrefly.bzl
f06e59f
Relocates pyrefly.bzl into tools/private and updates the aspect target reference in .bazelrc.
@rickeylev
Move Pyrefly aspect into tools/private/pyrefly directory
fb6a531
Relocates pyrefly.bzl under tools/private/pyrefly and updates .bazelrc label reference.
@rickeylev
Update tools/private/pyrefly/BUILD.bazel via Gazelle
286d28f
Synchronizes BUILD.bazel with Gazelle generated rules.
@rickeylev
Use //tools/private/pyrefly:pyrefly.bzl%pyrefly_aspect label in .bazelrc
4b15b38
Updates the aspect reference in .bazelrc to use the tools/private/pyrefly package path.
@rickeylev
Remove leftover pyrefly bzl_library targets from tools and tools/priv…
3f383d1
…ate BUILD files

Cleans up unused pyrefly bzl_library definitions now that pyrefly.bzl lives in tools/private/pyrefly.
@rickeylev
Remove tools/private/pyrefly/BUILD.bazel target
2e10394
Removes the unnecessary bzl_library target and BUILD.bazel from tools/private/pyrefly, updating .bazelrc to reference //tools/private:pyrefly/pyrefly.bzl%pyrefly_aspect.
@rickeylev
Add pyrefly_check rule under //tests/runfiles for target-integrated t…
15454f9
…ype checking

Implements pyrefly_check in tools/private:pyrefly/pyrefly.bzl taking targets as a label list, and instantiates runfiles_check in tests/runfiles/BUILD.bazel targeting //python/runfiles:runfiles.
@rickeylev
Restore tools/private/pyrefly/BUILD.bazel with Gazelle formatting and…
7e1644e
… update load labels
@rickeylev
Remove redundant build:pyrefly config from .bazelrc
1cd767a
@rickeylev
Mark pyrefly extension/toolchain as dev_dependency in MODULE.bazel an…
bd1c5fb
…d use default_visibility in tools/private/pyrefly/BUILD.bazel
@rickeylev
Convert pyrefly_check to test rule pyrefly_check_test
1f8e8b1
Defines pyrefly_check_test with test = True so running bazel test //tests/runfiles/... automatically discovers and executes runfiles_check as a test target.
@rickeylev
Wrap pyrefly_check in build_test in tests/runfiles/BUILD.bazel
7028d12
Restores pyrefly_check as a build rule in tools/private/pyrefly/pyrefly.bzl and tests it using standard build_test in tests/runfiles/BUILD.bazel.
@rickeylev
Hide build_test behind pyrefly_check_test macro
4ab6a4b
Encapsulates pyrefly_check rule and build_test into a reusable pyrefly_check_test macro in tools/private/pyrefly/pyrefly.bzl.
@rickeylev
Move tools/private/pyrefly to tests/support/pyrefly
5d5fae7
Relocates the pyrefly test helper package from tools/private/pyrefly to tests/support/pyrefly and updates load references.
@rickeylev
Merge upstream/main into use_pyrefly_runfiles_check
4dd0dfc
@rickeylev
Use tag-based Pyrefly opt-in with global aspect registration
6a5b071
Replaces the custom pyrefly_check wrapper rule with rules_pyrefly's
native opt_in_tags feature. Applies pyrefly_aspect globally via
.bazelrc while tagging //python/runfiles:runfiles for opt-in static
type checking.
@rickeylev
Gate Pyrefly aspect evaluation behind BZLMOD_ENABLED
e63101e
Prevents WORKSPACE-mode (non-Bzlmod) builds from failing due to
unresolved @rules_pyrefly repository references while preserving
opt-in tag-based static type checking under Bzlmod.
@rickeylev
Move BZLMOD_ENABLED check into pyrefly_check_test macro
d14c712
Top-level if statements are forbidden in Bazel BUILD files. Moving
the BZLMOD_ENABLED check inside the pyrefly_check_test macro
definition in pyrefly.bzl ensures clean BUILD file evaluation while
preserving Bzlmod-only target generation.
@rickeylev
Declare rules_pyrefly in internal_dev_deps for WORKSPACE mode
0b62db9
Adds rules_pyrefly repository definition to rules_python_internal_deps
in internal_dev_deps.bzl so package loading succeeds during WORKSPACE
mode builds. Removes non-existent bzl_library dependency target.
@rickeylev
Add comment explaining early exit when BZLMOD_ENABLED is False
10f59a0
Clarifies in pyrefly.bzl that Pyrefly type checking does not support
WORKSPACE mode and exits early when Bzlmod is not enabled.
@rickeylev
Use global aspect and WORKSPACE stub for rules_pyrefly
43649e1
Registers rules_pyrefly_stub in internal_dev_deps.bzl for WORKSPACE
mode so load() statements resolve, and adds global aspect flag to
.bazelrc to apply Pyrefly static type checking across tagged targets.
@rickeylev
Remove pyrefly_check_test macro invocation from tests/runfiles
bd8dad9
Removes the macro target invocation now that Pyrefly type checking is applied globally via aspect on tagged targets.
@rickeylev
Remove pyrefly_check_test macro and pyrefly_check rule
d4f11d6
Removes the unused macro and rule definitions, leaving only pyrefly_aspect in tests/support/pyrefly/pyrefly.bzl.
@rickeylev
Add no_gh_auth_token_in_cmdline workspace rule
47978ca
Adds an always-on workspace rule prohibiting the use of auth tokens in command line arguments.
@rickeylev
Merge remote-tracking branch 'upstream/main' into enable_pyrefly_pyth…
adeaadc
…on_targets
@rickeylev
Enable opt-out Pyrefly static type checking across Python targets
b0bff18
Enable Pyrefly type checking by default using opt-out enforcement.
Configure rules_pyrefly aspect and toolchain setup in sphinxdocs module.
Set --config=pyrefly by default in root and sphinxdocs .bazelrc files.
@rickeylev
Enable Pyrefly static type checking across remaining Python targets
6ce8842
Enable Pyrefly type checking across tests and sphinxdocs libraries to ensure
type safety, resolving typing diagnostics and adding necessary type ignores
for generated proto stubs.

- Remove no-pyrefly tags across sphinxdocs, test targets, and fixtures.
- Add TypedDict definitions and modernize type annotations in sphinx_build and bzl.py.
- Introduce _get_bzl_domain() helper in bzl.py and preserve @OverRide decorators.
- Simplify variable assignment in dependency_resolver.py.
- Add pyrefly enablement plan documenting findings and requirements.
@rickeylev
Merge remote-tracking branch 'upstream/main' into enable_pyrefly_pyth…
6a7d66e
…on_targets
@rickeylev
test(repl): restore test_module import in test_cannot_import_test_mod…
aa19cec
…ule_directly

The test asserts that importing a non-direct dependency raises
ModuleNotFoundError at runtime; keep the import with type ignore.
@rickeylev

rickeylev commented Aug 9, 2026

Copy link
Copy Markdown
Collaborator Author

Ready, PTAL

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

dougthor42
dougthor42 reviewed Aug 9, 2026
View reviewed changes
Comment thread .agents/rules/python.md Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread .agents/rules/python.md Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread examples/wheel/main.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread python/private/pypi/whl_installer/arguments.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread python/runfiles/runfiles.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread sphinxdocs/sphinxdocs/src/sphinx_bzl/bzl.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread sphinxdocs/sphinxdocs/src/sphinx_bzl/bzl.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread sphinxdocs/sphinxdocs/private/proto_to_markdown.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread tests/cc/py_extension/py_extension_pkg_test.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread tests/pytest_test/BUILD.bazel Resolved

Uh oh!

There was an error while loading. Please reload this page.

rickeylev added 9 commits August 9, 2026 07:36
@rickeylev
Address review comments on Pyrefly annotations and ignores
433ae08
Use specific error-code ignores with pyrefly syntax, annotate type narrowing
assertions with '# type assert', replace @dev_pip with @pypi in release tool tests,
and remove obsolete test tags.
@rickeylev
Fix mypy errors in runfiles library and tests
9e163c6
Add assertions to narrow Optional[Runfiles] and include mypy-specific type
ignores alongside pyrefly directives so both checkers pass.
@rickeylev
Fix return type annotation for Path.runfiles_root
dd1a434
Change return type from Self to Path to match Runfiles.root return type.
@rickeylev
Address review feedback on runfiles, repl, and docs
bfcd6d0
- Revert type ignores in debuggers.md docstring.
- Safely extract readline.__doc__ to avoid unsupported-operation on None.
- Use runfiles.CreateOrRaise() and Runfiles.root() in repl_template.py.
- Cast obj to Path in runfiles.py __new__ and _make_child to eliminate
  attribute ignores and type:ignore[misc].
@rickeylev
Use getattr in Path._make_child to avoid mypy superclass error
9157f96
Dynamically lookup _make_child on super() and cast to Path so both mypy
and pyrefly pass without explicit ignore comments.
@rickeylev
Simplify super()._make_child and clean debuggers doc example
89d4498
Remove type ignores from documentation sample in debuggers.md and simplify
Path._make_child invocation in runfiles.py with proper type disable annotations.
@rickeylev
Explain type ignores on Path._make_child
21d24af
Add comment explaining that _make_child is an internal CPython method in
Python < 3.12 omitted from typeshed stubs, requiring [misc] ignore for mypy
and [missing-attribute] ignore for pyrefly.
@rickeylev
Merge branch 'upstream/main' into enable_pyrefly_python_targets
e09a898
Sync with upstream/main to incorporate Runfiles.CreateOrRaise API.
@rickeylev
Clarify error-specific ignores rule in python.md
2685982
Add explicit instruction to use error-specific ignores instead of blanket
or placeholder ignores.
dougthor42
dougthor42 reviewed Aug 10, 2026
View reviewed changes
Comment thread sphinxdocs/sphinxdocs/private/proto_to_markdown.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread sphinxdocs/sphinxdocs/private/sphinx_build.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread sphinxdocs/sphinxdocs/src/sphinx_bzl/bzl.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread python/private/pypi/whl_installer/arguments.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread sphinxdocs/sphinxdocs/src/sphinx_bzl/BUILD.bazel Resolved

Uh oh!

There was an error while loading. Please reload this page.

rickeylev added 9 commits August 10, 2026 05:23
@rickeylev
Fix Sphinx method override signatures and remove bad-override disables
04d312c
Align parameter names (signode, contentnode) and types (location) in
sphinx_bzl with Sphinx base classes, eliminating bad-override suppressions.
@rickeylev
Restore pyrefly bad-override ignores in sphinxdocs and align signode …
53ad990
…param

Restore bad-override ignores needed due to untyped Sphinx/docutils parent
classes, align _BzlTarget.handle_signature parameter naming to signode, and
remove transient plan file from git tracking.
@rickeylev
Add explanatory comments to pyrefly bad-override ignore suppressions
552dc57
Document why bad-override ignores are necessary for Path.open (simplified
overload signature) and sphinx_bzl methods (untyped parent classes in
Sphinx/docutils).
@rickeylev
Restore NOTE comment in sphinx_bzl/BUILD.bazel
78a20cf
Restore comment explaining that sphinx_bzl provides the library on its own
and relies on the caller to provide runtime dependencies.
@rickeylev
Use collections.abc and builtin types instead of typing aliases
9aaef3a
Replace typing collection aliases (Tuple, List, Set, Sequence, Iterable,
Iterator, AbstractSet) and typing.Union with collections.abc protocols and
builtin generic types across tools, tests, and sphinx_bzl.
@rickeylev
Replace Optional[X] with X | None
6af1a5f
Replace typing.Optional annotations with union with None (X | None)
and enable postponed evaluation of annotations where needed.
@rickeylev
Clean up request arguments access, runfiles init, and Sequence typing
f43c5ad
- In sphinx_build.py, index request arguments directly instead of .get().
- In repl_test.py, use runfiles.CreateOrRaise().
- In wheelmaker.py, clean up obsolete noqa on Sequence.
@rickeylev
Enable future annotations in pathlib_test.py
2e43776
Add from __future__ import annotations to pathlib_test.py to enable
postponed evaluation of type annotations.
@rickeylev
Merge branch 'upstream/main' into enable_pyrefly_python_targets
d4dc460
@rickeylev

rickeylev commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator Author

PTAL

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

dougthor42
dougthor42 approved these changes Aug 10, 2026
View reviewed changes
@rickeylev
Merge branch 'upstream/main' into enable_pyrefly_python_targets
2522b2a
@rickeylev
rickeylev enabled auto-merge August 11, 2026 06:17
@rickeylev
rickeylev added this pull request to the merge queue Aug 11, 2026
Merged via the queue into bazel-contrib:main with commit b401c75 Aug 11, 2026
6 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@rickeylev
rickeylev deleted the enable_pyrefly_python_targets branch August 11, 2026 06:48
@aignas aignas mentioned this pull request Nov 8, 2026
Expand rules_python's type checking in CI to apply to remaining code #3353
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@dougthor42 dougthor42 dougthor42 approved these changes
@aignas aignas Awaiting requested review from aignas aignas is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@rickeylev @dougthor42
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.