-
Notifications
You must be signed in to change notification settings - Fork 431
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
Minimal code changes to support type hinting of db methods #1934
base: master
Are you sure you want to change the base?
Conversation
5eda9cd
to
459df7e
Compare
Some really nice examples in there of bugs that could happen if |
The |
This is an excellent example how the type hinting can identify poor design choices, such as proxies returning But I also don't think returning an empty object is good. Would it have a handle? Probably, because we used In my opinion, the cleanest solution is to raise |
As it stands, for an empty The comment in Which should it be? |
We have known for years that proxies returning I introduced the I'm only objecting to the first commit in this PR. |
If it is ultimately considered an error then I'll revise the code to raise an exception of a new type. It that turns out to be too painful, we always have the option to backtrack and return an empty object instead. By using a new exception type, we can identify the locations that were modified. Is that a reasonable approach? |
It could get interesting to start raising an exception instead of returning gramps/gramps/gen/proxy/private.py Lines 87 to 89 in ef5512c
|
The best approach is for a proxy never to return a handle for an object that needs to be filtered out. However, an interim solution is also acceptable, as long as we are heading in the right direction. Returning fully or partially redacted objects and raising exceptions are alternatives to returning |
Yes, excellent solution.
|
Yes, that should not return None. I'll wait to fix that those... I'm just going to fix bugs in #1941 |
7e71978
to
24c50a0
Compare
@@ -866,7 +866,7 @@ class object of a primary object. | |||
"event": self.db.has_event_handle, | |||
"place": self.db.has_place_handle, | |||
"source": self.db.has_source_handle, | |||
"citation": self.db.get_raw_citation_data, | |||
"citation": self.db.has_citation_handle, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Nick-Hall this one might be worth worth pushing to 6.0 as well. Let me know and I can make a separate PR
I think it is more of a performance problem, unnecessarily getting the citation DataDict
, just to check if the handle is a valid citation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Something like this is obviously a mistake and just a single line change. I think that we can accept it as a bug even if it isn't actually causing a problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. I'll split out later.
24c50a0
to
4bf4452
Compare
700304a
to
f6e27aa
Compare
Default to returning True so that all objects are included by default
gfilter_none can return None gfilter does not return None and raises an error
Use `yield from ()` rather than `return` and `return []`
…ded in the result
…ck if a handle is valid
f6e27aa
to
151348e
Compare
The original first commit,
which provoked much discussion is now dropped from this PR 🎆 I think this PR ready for review |
5294897
to
38883b7
Compare
…check for handle existence. As a result it can get the object directly rather then convert the raw data into an object
38883b7
to
494706e
Compare
libmixin.py now has the following code:
I'm hypothesising that
The only way #1 can be wrong is through object deletion, after the handle has been obtained. In the context of this code, I do not believe that this happens. Your thoughts welcome, but I'm not making this change in this PR! |
I hope that reference handles are removed, but I am not 100% sure. If there are left over handles, I think we should treat that as a bug, and that the database is corrupted. |
In future, this allows the return type hint of <object> | None for consistency with other db implementations
These are the code changes split out from #1919
Each commit fixes one thing.
The first 7 commits are required for mypy to pass the type hinted code which will be introduced in a later PR #1919
The last 3 commits fix a spelling mistake and rename parameters for consistency and clarity. These could be moved to a separate PR if required.