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 especially Tolerance(absolute=..., relative=...)) should not implicitly update TOL.
- Provide an explicit API for updating the global tolerance, e.g.
TOL.update(...) / TOL.set(...), and/or a dedicated helper like set_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
Tolerance in which case Tolerance() actually returns a new instance whereas TOL is 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.relative
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 callingTolerance(...).Details
Is your feature request related to a problem? Please describe.
Right now
Tolerancebehaves like a singleton:Tolerance()returnsTOL, and callingTolerance(absolute=...)appears to create/configure a new instance but actually mutates the globalTOL. 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.TOL.update(...)/TOL.set(...), and/or a dedicated helper likeset_default_tolerance(...).Tolerance()private or raise error after the first instance has been created.Describe alternatives you've considered
Tolerancein which caseTolerance()actually returns a new instance whereasTOLis the global instance.Additional context
Current behavior example: