Skip to content

Add stubs for JACK-Client #4809

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 24, 2021

Conversation

markspolakovs
Copy link
Contributor

No description provided.


JackPositionT = Any

class CBufferType:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only exists because I couldn't for the life of me find the type definition for cffi's buffer type; if someone can think of a better way of doing this I'd appreciate it!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See perhaps python/typing#593 (summary: there's no good way yet).

@markspolakovs markspolakovs force-pushed the markspolakovs/add-jack-client branch from fffbc1d to 0f4913b Compare December 12, 2020 16:24

NDArray = Any # FIXME: no typings for numpy arrays

JackPositionT = Any
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a raw C type (https://github.com/spatialaudio/jackclient-python/blob/master/src/jack.py#L220) and I'm not sure how to type it correctly so I left it as Any.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe type it as a private class (class _JackPositionT: ...).

Also, all types that don't exist at runtime should be prefixed with underscores.

@markspolakovs markspolakovs force-pushed the markspolakovs/add-jack-client branch from 0f4913b to ed51499 Compare December 12, 2020 17:38
@markspolakovs
Copy link
Contributor Author

markspolakovs commented Dec 13, 2020

Looks (to my untrained eye) like the mypy failure is unrelated (errors from google.protobuf)

Copy link
Member

@JelleZijlstra JelleZijlstra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not familiar with this library, but spotchecked a few functions and they look good. I left a few minor comments.


NDArray = Any # FIXME: no typings for numpy arrays

JackPositionT = Any
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe type it as a private class (class _JackPositionT: ...).

Also, all types that don't exist at runtime should be prefixed with underscores.


JackPositionT = Any

class CBufferType:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See perhaps python/typing#593 (summary: there's no good way yet).


class CBufferType:
@overload
def __getitem__(self, key: int) -> str: ...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The str/bytes difference here looks odd. Maybe we need cffi stubs with a more precise type though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got that from the cffi docs:

buf[:] or bytes(buf): copy data out of the buffer, returning a regular byte string (or buf[start:end] for a part)
buf[:] = newstr: copy data into the buffer (or buf[start:end] = newstr)
len(buf), buf[index], buf[index] = newchar: access as a sequence of characters.

It's entirely possible I've misinterpreted them though

@hauntsaninja
Copy link
Collaborator

stubtest has some complaints, which look valid on spot check:

jack.CBufferType is not present at runtime
jack.Client.__init__ is inconsistent, stub does not have argument "use_exact_name"
jack.Client.__init__ is inconsistent, stub does not have argument "no_start_server"
jack.Client.__init__ is inconsistent, stub does not have argument "servername"
jack.Client.__init__ is inconsistent, stub does not have argument "session_id"
jack.Client.set_port_connect_callback is inconsistent, runtime argument "callback" has a default value but stub argument does not
jack.Client.set_port_registration_callback is inconsistent, runtime argument "callback" has a default value but stub argument does not
jack.Client.set_port_rename_callback is inconsistent, runtime argument "callback" has a default value but stub argument does not
jack.Client.set_timebase_callback is inconsistent, runtime argument "callback" has a default value but stub argument does not
jack.JackErrorCode.__init__ is inconsistent, stub does not have argument "message"
jack.JackErrorCode.__init__ is inconsistent, stub does not have argument "code"
jack.JackErrorCode.__init__ is inconsistent, runtime does not have *args argument "args"
jack.JackOpenError.__init__ is inconsistent, stub does not have argument "name"
jack.JackOpenError.__init__ is inconsistent, stub does not have argument "status"
jack.JackOpenError.__init__ is inconsistent, runtime does not have *args argument "args"
jack.OwnMidiPort.__init__ is inconsistent, stub does not have *args argument "args"
jack.Port.__init__ is inconsistent, stub does not have argument "port_ptr"
jack.Port.__init__ is inconsistent, stub does not have argument "client"
jack.Ports.__init__ is inconsistent, stub does not have argument "client"
jack.Ports.__init__ is inconsistent, stub does not have argument "porttype"
jack.Ports.__init__ is inconsistent, stub does not have argument "flag"
jack.Status.__init__ is inconsistent, stub does not have argument "code"
jack.TransportState.__init__ is inconsistent, stub does not have argument "code"

@markspolakovs markspolakovs force-pushed the markspolakovs/add-jack-client branch from ed51499 to 1ddb74c Compare December 14, 2020 13:23
@markspolakovs
Copy link
Contributor Author

@JelleZijlstra @hauntsaninja Addressed.

@hauntsaninja I added types for the constructors of the various internal classes (Port, Status, etc.) although I left a couple as Any - the docs say that those classes aren't meant to be user-instantiable anyway, so I wasn't quite sure on the best way to handle it

@markspolakovs markspolakovs force-pushed the markspolakovs/add-jack-client branch 2 times, most recently from faab5e8 to b1d1603 Compare December 14, 2020 13:28
@markspolakovs markspolakovs force-pushed the markspolakovs/add-jack-client branch from b1d1603 to 3f4210c Compare December 14, 2020 13:31
Copy link
Collaborator

@hauntsaninja hauntsaninja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this looks good to me!

@srittau srittau merged commit 0fd00f0 into python:master Jan 24, 2021
@markspolakovs markspolakovs deleted the markspolakovs/add-jack-client branch January 24, 2021 13:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants