We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
A lot of methods need to check if the input is None and use either the _ptr attribute of the input or call the C function with ffi.NULL:
None
_ptr
ffi.NULL
def method(self, obj: SomePtrType | None) -> None: if obj is None: lib.something(self._ptr, ffi.NULL) else: lib.something(self._ptr, obj._ptr)
Having a helper function which either returns the _ptr attribute or ffi.NULL the code could be reduced to:
def method(self, obj: SomePtrType | None) -> None: obj_ptr = ptr_or_null(obj) lib.something(self._ptr, obj_ptr)
IMO it is a lot easier to read and to type.
Could be reduced to a one-liner, though:
def method(self, obj: SomePtrType | None) -> None: lib.something(self._ptr, ptr_or_null(obj))
The text was updated successfully, but these errors were encountered:
Added helper function to return either _ptr attribute or ffi.NULL
cacc029
This helper function checks if the input is None and returns ffi.NULL, otherwise the _ptr attribute. Closes flacjacket#160.
Successfully merging a pull request may close this issue.
A lot of methods need to check if the input is
None
and use either the_ptr
attribute of the input or call the C function withffi.NULL
:Having a helper function which either returns the
_ptr
attribute orffi.NULL
the code could be reduced to:IMO it is a lot easier to read and to type.
Could be reduced to a one-liner, though:
The text was updated successfully, but these errors were encountered: