robotpy / pyntcore

Moved to https://github.com/robotpy/mostrobotpy
2 stars 5 forks source link

GetXXX defaults should accept any python object #3

Closed virtuald closed 4 years ago

virtuald commented 4 years ago

Currently, they only allow you to pass in the same type, but pynetworktables will allow any python object.

I think these can be done via the low level NT api?

[](NetworkTable * nt, wpi::StringRef key, py::object defaultValue) -> py::object {
  auto entry = nt->GetEntry(key);
  auto value = GetEntryValue(entry.handle());
  if (!value->IsBoolean()) {
  return defaultValue;
  }
  return value->GetBoolean();
}

Of course, there's a lot of duplication we're doing here (this is exactly what NetworkTableEntry does)... maybe there's a way to override some of it?

virtuald commented 4 years ago

Also, the same thing applies to NetworkTable and NetworkTableEntry APIs. Should we apply the override to only one or both?