Skip to content

Allow customizing the treatment of literals in conversion #13

Open

Description

@florian-rabe

The treatment of the OpenMath literals (integer, float, string, byte array) is currently hard-coded in the convert methods.

The current treatment is a good defualt, but it should be possible to customize it.

One option, considering issue #12, is to simply use methods for this that can be overridden by other classes.

Activity

  1. defeo commented on Feb 21, 2018

    @defeo
    Collaborator

    You mean, like this:

    >>> from openmath import *
    >>> i = convert.to_openmath(1)
    >>> i
    OMInteger(integer=1, id=None)
    >>> convert.to_python(i)
    1
    >>> convert.register_to_python(openmath.OMInteger, lambda x: "Hello")
    >>> convert.to_python(i)
    'Hello'
  2. nthiery commented on May 18, 2018

    @nthiery
    Collaborator

    Ah, right, it's already possible to customize it. The code itself could use it, replacing
    the last 2 lines of:

    def to_python(omobj):
        """ Convert OpenMath object to Python """
        if omobj.__class__ in _conv_to_py:
            return _conv_to_py[omobj.__class__](omobj)
        elif isinstance(omobj, om.OMInteger):
            return omobj.integer
    

    by a call to register_to_python at initialization time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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