Drop __firstlineno__ on ProxyBase instances - #8045
Conversation
We don't want to define `__firstlineno__` on instances of `ProxyBase`. - We don't want to proxy through the original `__firstlineno__`, since we've updated `__module__`, so the line numbers would no longer be accurate. - We don't want to use our `__firstlineno__` for the same reason - they map to a different file than `__module__`. Dropping this attribute causes tools like `inspect.getsourcelines` to error appropriately, saying the source code cannot be found. Note that any _methods_ inspected on our proxy classes will still report the original sklearn code (as intended), it's just grabbing the whole class that won't work. The main place this shows up is some docstring tests in the sklearn repo - previously these were implicitly skipped because `getsourcelines` would error. The recent metaclass changes led to this not erroring in _all_ python versions, leading to failures in our nightlies. This PR fixes things so that we drop `__firstlineno__` uniformly, leading to the tests to pass/skip in all python versions, reverting to the previous behavior.
📝 WalkthroughSummary by CodeRabbit
WalkthroughThe PR modifies ChangesProxy Class Metadata Cleanup
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Possibly related PRs
Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Review rate limit: 9/10 reviews remaining, refill in 6 minutes. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@python/cuml/cuml/accel/estimator_proxy.py`:
- Around line 246-257: Add a regression test that verifies deletion of
__firstlineno__ on proxy classes: create a proxy class instance (the class
produced by the estimator proxy metaclass in estimator_proxy.py) and assert that
inspect.getsource(proxy_class) raises (e.g., OSError) while
inspect.getsource(proxy_class.some_method) or
inspect.getsource(proxy_instance.some_method) still returns the method source;
this ensures class-level source inspection fails after del cls.__firstlineno__
but method-level lookup remains intact. Include the test alongside existing
estimator_proxy tests and reference the proxy class created by the metaclass and
the cls.__firstlineno__ behavior in the test name/comment.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 48bbe255-af8c-4159-8677-f4289be825b2
📒 Files selected for processing (1)
python/cuml/cuml/accel/estimator_proxy.py
|
/merge |
We don't want to define
__firstlineno__on instances ofProxyBase.__firstlineno__, since we've updated__module__, so the line numbers would no longer be accurate.__firstlineno__for the same reason - they map to a different file than__module__.Dropping this attribute causes tools like
inspect.getsourcelinesto error appropriately, saying the source code cannot be found. Note that any methods inspected on our proxy classes will still report the original sklearn code (as intended), it's just grabbing the whole class that won't work.The main place this shows up is some docstring tests in the sklearn repo - previously these were implicitly skipped because
getsourcelineswould error. The recent metaclass changes led to this not erroring in all python versions, leading to failures in our nightlies.This PR fixes things so that we drop
__firstlineno__uniformly, leading to the tests to pass/skip in all python versions, reverting to the previous behavior.