Skip to content

Add test and fix stub for sklearn.config_context#3155

Open
fhoehle wants to merge 2 commits into
facebook:mainfrom
fhoehle:fh.fix-sklearn-config_context
Open

Add test and fix stub for sklearn.config_context#3155
fhoehle wants to merge 2 commits into
facebook:mainfrom
fhoehle:fh.fix-sklearn-config_context

Conversation

@fhoehle

@fhoehle fhoehle commented Apr 15, 2026

Copy link
Copy Markdown

Summary

This PR adds a new test asserting that the sklearn.config_context context manager is correctly understood.
The initial failing test is fixed by correcting the corresponding sklearn.config_context type hint and adding the contextlib.contextmanager decorator.

Issue #3154 describes the observed error. The originating cause is the incorrect sklearn-stub in the pyrefly_bundled crate.

The deprecation warning regarding Iterator[None] is mitigated by replacing it with Generator

Test Plan

  • Executing the new (failing) test at 03b707d7bb6aeb55d9c5f2b6dd7b6e7367fe43a4, which failed with the above-described bad-context-manager error.
    cargo test -p pyrefly --lib test_sklearn
  • Successful execution at HEAD of this branch
  • Successful run of test.py
@meta-cla

meta-cla Bot commented Apr 15, 2026

Copy link
Copy Markdown

Hi @fhoehle!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@meta-cla

meta-cla Bot commented Apr 15, 2026

Copy link
Copy Markdown

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@rchen152 rchen152 left a comment

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.

Thanks for the PR! Pyrefly's bundled sklearn stubs are mirrored from here:

"repository": "https://github.com/microsoft/python-type-stubs",
. So rather than editing our bundled copy, it would be better to fix the stubs upstream and then bundle a fresh copy.

(If you get pushback on or lack of response to an upstream PR, we can consider doing a local patch instead. We'd need to record the patch somewhere, so we know what we've modified.)

@fhoehle

fhoehle commented Apr 16, 2026

Copy link
Copy Markdown
Author

Many thanks for pointing out the mirroring I oversaw it. After updating the upstream source what are the concrete steps to propagate the change? The update.py script seems to update the python/typeshed stubs. I assume the stubs listed in stubs_metadata.json are updated manually so I will include the update here after the upstream change is merged. Is that correct?

@rchen152

Copy link
Copy Markdown
Contributor

@jvansch1 originally added the bundled stubs and can correct me if I'm wrong, but I believe we just manually copied them over.

@jvansch1

Copy link
Copy Markdown
Contributor

@fhoehle Like @rchen152 pointed out the process currently is to just manually copy them into the Pyrefly repo. Instead of doing this we could replace the existing stubs with a new version of the stubs.

@github-actions

Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had recent activity for more than 2 weeks.

If you are still working on this this pull request, please add a comment or push new commits to keep it active. Otherwise, please unassign yourself and allow someone else to take over.

Thank you for your contributions!

@github-actions github-actions Bot added the stale label May 13, 2026
@fhoehle

fhoehle commented May 14, 2026

Copy link
Copy Markdown
Author

Current status: Waiting for an upstream maintainer to review the proposed changes.

@github-actions github-actions Bot removed the stale label May 15, 2026
@rchen152

Copy link
Copy Markdown
Contributor

@fhoehle Thank you for opening a PR with microsoft/python-type-stubs. It looks like the repo may be unmaintained now, which is unfortunate.

@jvansch1 Do you have any thoughts on what to do here? I was originally thinking that if we diverge from the upstream stubs, we should maintain a stack of patches to make it easier to cleanly reapply our changes on top of a new version, but maybe that's unnecessary if the original repo is inactive.

@fhoehle

fhoehle commented May 19, 2026

Copy link
Copy Markdown
Author

@rchen152 I opened an upstream issue asking about maintainership and also pinged a Pylance maintainer who handles their releases. I'd propose we wait a little to see if anyone responds and clarifies the maintenance.

fhoehle added 2 commits June 30, 2026 16:54
Summary: Refresh the sklearn stubs to the upstream commit, fixing
`config_context` to type-check as a context manager and adding the `"polars"` option to `set_output`.
Add basic tests covering the sklearn stubs.
@fhoehle fhoehle force-pushed the fh.fix-sklearn-config_context branch from dcf6daf to 06b4b06 Compare June 30, 2026 15:01
@github-actions github-actions Bot added size/s and removed size/m labels Jun 30, 2026
@fhoehle

fhoehle commented Jun 30, 2026

Copy link
Copy Markdown
Author

Hi @rchen152 — the upstream PR is now merged, so I've bumped the vendored sklearn-stubs to that commit.
I also changed the added test test_sklearn_config_context_is_context_manager to exercise the real bundled stubs rather than an inline sklearn-stub — i.e., no hand-written copy. It ignores missing-source-for-stubs because sklearn isn't installed in the test env.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

3 participants