<commit_before>#API for publishing and subscribing to message topics

type Publisher{MsgType<:MsgT}
    o::PyObject

    function Publisher(topic::String; kwargs...)
        rospycls = _get_rospy_class(MsgType)
        return new(__rospy__.Publisher(topic, rospycls; kwargs...))
    end
end
Publisher{MsgType<:MsgT}(topic::String, ::Type{MsgType}; kwargs...) =
    Publisher{MsgType}(topic; kwargs...)

function publish{MsgType<:MsgT}(p::Publisher{MsgType}, msg::MsgType)
    pycall(p.o["publish"], PyAny, convert(PyObject, msg))
end

type Subscriber{MsgType<:MsgT}
    o::PyObject
    callback::Function

    function Subscriber(topic::String, cb::Function, cb_args = (); kwargs...)
        rospycls = _get_rospy_class(MsgType)
        jl_callback(msg::PyObject) = cb(convert(MsgType, msg), cb_args...)
        return new(
            __rospy__.Subscriber(topic, rospycls, jl_callback; kwargs...),
            jl_callback
        )
    end
end
Subscriber{MsgType<:MsgT}(
    topic::String,
    ::Type{MsgType},
    cb::Function,
    cb_args=();
    kwargs...
) = Subscriber{MsgType}(topic, cb, cb_args; kwargs...)

function _get_rospy_class(typ::DataType)
    rospycls =
        try
            _rospy_classes[RobotOS._typerepr(typ)]
        catch ex
            if isa(ex, KeyError)
                error("Type ($typ) is not generated")
            else
                error("Type ($typ) is not a valid message type")
            end
        end
    rospycls
end<commit_msg>Added type constraint to callback args for Subscriber<commit_after>#API for publishing and subscribing to message topics

type Publisher{MsgType<:MsgT}
    o::PyObject

    function Publisher(topic::String; kwargs...)
        rospycls = _get_rospy_class(MsgType)
        return new(__rospy__.Publisher(topic, rospycls; kwargs...))
    end
end
Publisher{MsgType<:MsgT}(topic::String, ::Type{MsgType}; kwargs...) =
    Publisher{MsgType}(topic; kwargs...)

function publish{MsgType<:MsgT}(p::Publisher{MsgType}, msg::MsgType)
    pycall(p.o["publish"], PyAny, convert(PyObject, msg))
end

type Subscriber{MsgType<:MsgT}
    o::PyObject
    callback::Function

    function Subscriber(
        topic::String, cb::Function, cb_args::(Any...,) = (); kwargs...
    )
        rospycls = _get_rospy_class(MsgType)
        jl_callback(msg::PyObject) = cb(convert(MsgType, msg), cb_args...)
        return new(
            __rospy__.Subscriber(topic, rospycls, jl_callback; kwargs...),
            jl_callback
        )
    end
end
Subscriber{MsgType<:MsgT}(
    topic::String,
    ::Type{MsgType},
    cb::Function,
    cb_args::(Any...,) = ();
    kwargs...
) = Subscriber{MsgType}(topic, cb, cb_args; kwargs...)

function _get_rospy_class(typ::DataType)
    rospycls =
        try
            _rospy_classes[RobotOS._typerepr(typ)]
        catch ex
            if isa(ex, KeyError)
                error("Type ($typ) is not generated")
            else
                error("Type ($typ) is not a valid message type")
            end
        end
    rospycls
end
{'fraction_non_alphanumeric': 0.1345646437994723, 'fraction_numerical': 0.0, 'mean_word_length': 2.8103015075376883, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5953014', 'n_tokens_mistral': 988, 'n_tokens_neox': 983, 'n_words': 201}