r/codereview • u/BiteCode_Dev • 24d ago
Removing a stored-but-unread constructor dependency: what would you check first?
I'm looking for feedback on a small cleanup candidate in mypy, the Python static type checker. This is third-party code, not my implementation, and I haven't established that removing the parameter is safe.
In the pinned version of PatternChecker, a plugin is accepted and stored, but the class does not read it. These are excerpts from the class, with unrelated members and initialization omitted:
# Currently unused
plugin: Plugin
def __init__(
self, chk: TypeCheckerSharedApi, msg: MessageBuilder,
plugin: Plugin, options: Options
) -> None:
self.chk = chk
self.msg = msg
self.plugin = plugin
# ...Full class and constructor at the reviewed commit.
The parameter and the unused marker were already present in PR #10191, merged on 18 January 2022. The age prompted the review; it does not prove the dependency is unnecessary. The observation is limited to reads inside this class, not every possible consumer.
The candidate change would remove the attribute declaration, constructor parameter and assignment, then update callers. That makes the constructor express fewer dependencies, but could break subclasses, external callers or code that reads the attribute dynamically.
Before proposing that change, I would check constructor call sites, subclass contracts, accesses to the stored attribute, and the project's compatibility policy, then run the relevant tests. I haven't completed those checks or run mypy's full suite.
What would your review require before accepting this removal? In particular, when would you keep the unused parameter for compatibility or constructor consistency, and when would you remove it or deprecate it first?
Disclosure: this account is run by BiteCode. AI assisted with preparing this write-up; the linked source is the basis for the observation.
1
u/CCodeSI 23d ago
At that commit the checks are short, so they're worth doing before you decide anything:
checker.py:553, whereTypeCheckerbuilds it asPatternChecker(self, self.msg, self.plugin, options). No subclasses ofPatternCheckeranywhere in the repo, and nothing outsidecheckpattern.pyreads.pluginoff it. Callers only usepattern_checker.accept(...).PatternCheckerisn't part of mypy's public surface. The plugin API is the documented extension point, and even that isn't promised stable. A third-party plugin could technically reachchk.pattern_checker.plugin, but that's a private attribute of a private class. I wouldn't hold a cleanup back for it, and a deprecation cycle would be overkill.# Currently unusedmarker reads like a placeholder for future plugin hooks on match statements, mirroringExpressionChecker, which takespluginand actually uses it. That's the real question for the maintainers: is a pattern-matching plugin hook still planned? If yes, they'll probably want to keep it. If not, removing it is a two-line change.So what I'd ask for in review: a grep showing no other readers, the one call site updated, the full test suite passing (it's mypyc-compiled, so a compiled build too, not just the interpreted run), and a short note in the PR asking whether the hook was ever planned. Small PRs like this get merged much faster when they answer that question up front instead of leaving it for a maintainer.