Removed implicit singleton behavior of Tolerance.#1510
Removed implicit singleton behavior of Tolerance.#1510chenkasirer wants to merge 1 commit intomainfrom
Conversation
…es can be created and global instance can be explicitly modified
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1510 +/- ##
==========================================
+ Coverage 62.26% 62.30% +0.04%
==========================================
Files 208 208
Lines 22452 22475 +23
==========================================
+ Hits 13979 14003 +24
+ Misses 8473 8472 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR removes the implicit singleton behavior of Tolerance, so Tolerance(...) now returns independent instances while TOL remains the explicit global instance. It also introduces explicit APIs for mutating global tolerance state (TOL.update and TOL.temporary) and documents these behaviors, plus updates the changelog and tests accordingly.
Changes:
- Refactored
compas.tolerance.Toleranceto be a regular class (no singleton), while keeping a module-levelTOL = Tolerance()as the shared global instance. - Added
Tolerance.update(...)andTolerance.temporary(...)to support explicit, scoped modifications of tolerance settings, and updated module/class docstrings. - Extended
tests/compas/test_tolerance.pyandCHANGELOG.mdto cover and document the new behavior.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/compas/tolerance.py |
Removes singleton machinery, adds explicit mutation helpers (update, temporary), extends documentation, and keeps TOL as a dedicated global instance. |
tests/compas/test_tolerance.py |
Adds tests to verify independent Tolerance instances, explicit TOL.update, and scoped TOL.temporary behavior (including restoration on exceptions). |
CHANGELOG.md |
Documents the new TOL.update/TOL.temporary APIs and the change away from the singleton Tolerance pattern. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| saved = { | ||
| "unit": self._unit, | ||
| "absolute": self._absolute, | ||
| "relative": self._relative, | ||
| "angular": self._angular, |
There was a problem hiding this comment.
temporary() saves and restores self._unit, but updates the unit via self.update(unit=...), which assigns to self.unit (a plain instance attribute, since there is no unit property). As a result, using TOL.temporary(unit=...) will change TOL.unit permanently instead of reverting it on context exit, unlike the other fields that correctly round-trip via their private attributes. To make the context manager behave consistently and avoid accidental global state changes for unit, the implementation should either snapshot and restore self.unit (not self._unit) or introduce a proper unit property that proxies to _unit and make both update and temporary use that.
Closes #1509
Tolerancewhich was leading to accidental global state modification.Tolerance(...)now creates independent instances ofToleranceTolerance.update()to update an instance in-place (e.g.TOL)Tolerance.temporary()context manager for local modifications of tolerance.What type of change is this?
Checklist
Put an
xin the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.CHANGELOG.mdfile in theUnreleasedsection under the most fitting heading (e.g.Added,Changed,Removed).invoke test).invoke lint).compas.datastructures.Mesh.