Skip to content

Proposal: changes to the behavior or Tolerance/TOL #1509

@chenkasirer

Description

@chenkasirer

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions