Move make_identifier function to collect.py#1215
Conversation
| @@ -0,0 +1,14 @@ | |||
| from typing import Any, NamedTuple | |||
|
|
|||
| TaskwarriorData = dict[str, Any] | |||
There was a problem hiding this comment.
I find this name confusing because it is unclear that it is data for a single task. (Everything in the taskwarrior database is "taskwarrior data".)
I had the thought that it might be ideal to align naming with taskchampion but I'm not strongly opinionated. Here are some ideas and rambling thoughts:
Task: Don't all data types hold data? What are we trying to communicate with "data" thatTaskwouldn't cover? Or perhaps we should differentiate fromtaskw.Task?- TaskData: Similar to what you have, but taskchampion's data structure is slightly higher level.
- TaskMap: The most directly comparable data structure, but named after the rust-specific
HashMap.
On the other hand, does such a simple data structure really deserve a custom type? What's the point?
There was a problem hiding this comment.
I find this name confusing because it is unclear that it is data for a single task. (Everything in the taskwarrior database is "taskwarrior data".)
Good point, that name is bad.
On the other hand, does such a simple data structure really deserve a custom type? What's the point?
Here is my chain of thoughts:
- We should stop passing dicts everywhere, as it's really hard to understand what these dicts are exactly
- We should use our own
Taskobject, and that's whatto_taskwarrior()should return, but that's a separate issue. - In the meantime, let's have a type alias, so we know where this dict is used (so we can modify all the types all at once, when switching to a real model (pydantic, probably).
But I can remove this type for now.
There was a problem hiding this comment.
I agree with your line of reasoning but I also think it should be removed for now until we have a specified data type that actually constrains the value it holds.
There was a problem hiding this comment.
What is the advantage of centralizing types here rather than in the modules in which they're instantiated? To me this pattern seems to obfuscate the dependency graph between modules and possibly encourage such dependence. (Using a type which is only instantiated in one module is effectively dependence on that module.)
There was a problem hiding this comment.
To be honest, the main reason to put it there is laziness, as I was sure it wouldn't create any dependency issue, but I mostly agree with you.
Would you move this code along Issue and Service in services/__init__.py, or in a new file services/types.py ?
There was a problem hiding this comment.
It's such a small amount of code that I would just put it in _init__.py.
Part of the reason I was asking is that I've seen this pattern in other code bases and wondered if there was something special about types.py or if that was considered a best practice for some reason. I think your answer confirmed that there is nothing special about it and no reason to break it out unless we feel a module has become too big.
There was a problem hiding this comment.
On bigger codebases, I still think it improves readability, like most projects choose to have an exceptions.py. But I have no problem with dropping this for now
There was a problem hiding this comment.
Would you move this code along
IssueandServiceinservices/__init__.py, or in a new fileservices/types.py?
Is there a reason not to put them in collect.py, the place where they originate and db.py was already importing from?
There was a problem hiding this comment.
Good point, I moved it back to collect.py
| record = TaskConstructor(issue).get_data_to_sync() | ||
| yield record |
There was a problem hiding this comment.
| record = TaskConstructor(issue).get_data_to_sync() | |
| yield record | |
| yield TaskConstructor(issue).get_data_to_sync() |
e8e23de to
3315a89
Compare
|
Turns out I had a
|
3315a89 to
b2bb879
Compare
in aggregate_issues, we have both the Issue object and the deserialized data, so we can compute the identifier without relying on a fragile iteration on list of key_lists Also add some more precise typing
config/__init__.py now only imports objects for the public API get_service function is now defined in services/__init__.py
b2bb879 to
56754e9
Compare
It isn't clear to me that these changes are desirable. Could they be dropped now that the types are in collect.py? |
|
I'd keep the change on If we make sure of that (config not depending on anything), then I can revert the change on |
|
Keeping |
in aggregate_issues, we have both the Issue object and the deserialized data, so we can compute the identifier without relying on a fragile iteration on list of key_lists Also add some more precise typing