-
Notifications
You must be signed in to change notification settings - Fork 117
Open
Description
Feature Request
As a developer/user of compas.tolerance, I want changing the global tolerance (TOL) to be explicit and unsurprising so that I don’t accidentally modify global state by calling Tolerance(...).
Details
Is your feature request related to a problem? Please describe.
Right now Tolerance behaves like a singleton: Tolerance() returns TOL, and calling Tolerance(absolute=...) appears to create/configure a new instance but actually mutates the global TOL. This is easy to miss and can cause hard-to-track side effects.
Describe the solution you'd like
Make it very clear when global state is modified. For example:
Tolerance()(and especiallyTolerance(absolute=..., relative=...)) should not implicitly updateTOL.- Provide an explicit API for updating the global tolerance, e.g.
TOL.update(...)/TOL.set(...), and/or a dedicated helper likeset_default_tolerance(...). - Possibly, make
Tolerance()private or raise error after the first instance has been created.
Describe alternatives you've considered
- Perhaps it should be even possible to create standalone instances of
Tolerancein which caseTolerance()actually returns a new instance whereasTOLis the global instance.
Additional context
Current behavior example:
from compas.tolerance import TOL, Tolerance
assert TOL is Tolerance()
tol = Tolerance(absolute=0.01, relative=0.001) # looks like a new instance
assert tol.absolute == TOL.absolute # but it actually updated global state
assert tol.relative == TOL.relativeMetadata
Metadata
Assignees
Labels
No labels