def __new__(cls, name, value=None):
    """Get or create a new symbol instance.

        :param name: String representing the internal name.  `Symbol`:class:
               instances are unique (singletons) in the context of this
               argument.  ``#`` and spaces are invalid characters to allow
               comments.

        :param value: Any value compatible with Python `bool` or `int` types.
               `None` is used as a special value to create a value using the
               name hash.

        """
    from sys import intern as unique
    name = unique(name)
    if name:
        if value is None:
            value = hash(name)
        res = cls._instances.get(name)
        if res is None:
            if isinstance(value, int):
                res = super().__new__(cls, value)
                cls._instances[name] = res
            else:
                msg = (
                    'instancing "{}" with name "{}" and incorrect value "{}" of type "{}"'
                    )
                cn, vt = cls.__name__, type(value).__name__
                raise TypeError(msg.format(cn, name, value, vt))
        elif res != value:
            msg = 'value "{}" mismatch for existing instance: "{}"'
            raise ValueError(msg.format(value, name))
        return res
    else:
        raise ValueError('name must be a valid non empty string')
