gramps icon indicating copy to clipboard operation
gramps copied to clipboard

Fix IsMoreThanNthGenerationDescendantOf.init_list() typing

Open stevenyoungs opened this issue 8 months ago • 3 comments

The person argument of IsMoreThanNthGenerationDescendantOf.init_list() is typed to expect a Person From IsMoreThanNthGenerationDescendantOf.prepare() a parameter of type DataDict | None was passed. From within IsMoreThanNthGenerationDescendantOf.init_list a recursive call is made passing a Person object.

Unify so that the parameter always has the type DataDict | None

stevenyoungs avatar Mar 08 '25 16:03 stevenyoungs

Most of the filter init_list methods seem to take a primary object rather than a DataDict. Have look at the init_list method in the IsLessThanNthGenerationDescendantOf rule.

I think that we should leave this until v6.1 unless there is a real bug associated with it.

Nick-Hall avatar Mar 11 '25 17:03 Nick-Hall

Most of the filter init_list methods seem to take a primary object rather than a DataDict. Have look at the init_list method in the IsLessThanNthGenerationDescendantOf rule.

I chose to standardise on DataDict as it will be lightly faster. I think init_list is an internal method so we do not need to be consistent across the different classes. In this class a DataDict is sufficient. In other filters, the true object may be required. There's a general decision to be made here. A DataDict and the true object are designed to be interchangeable. As typing is introduced we need guidance on what pattern to follow in situations where a DataDict provides sufficient functionality:

  • person: Person
  • person: DataDict
  • person: Person | DataDict

The last option offers the most flexibility, allowing the calling code to provide whichever type is most convenient, at the expense of a little more typing when defining the method.

I think that we should leave this until v6.1 unless there is a real bug associated with it.

Agreed. So long as we do not make any other code change that exposes the lint error in 6.0, no need to fix in 6.0.

stevenyoungs avatar Mar 12 '25 21:03 stevenyoungs

If we make Person be a protocol (like we're thinking Database should be) then that might work. Unless one is importing both gen.lib.Person and a new typing.Person. I guess they might need different names.

dsblank avatar Mar 12 '25 22:03 dsblank