Closed mrwilson closed 3 years ago
This is great, thanks for taking a look!
I like the approach of making the election the top level with the other dates falling out of it.
A couple of thoughts after reading the diff - I've not left line comments as I'm not sure they're very useful at the moment.
Election
, rather than passing it for each date type - did you have a reason for adding it to each date type?Election
to use - have you thought about this case? Without it, I can see client application having to perform this logic, so I think it's worth including in the library somewhere. (e.g, include the for_id
concept we have at the moment)n
date types, it might be nice to be able to get a list of them all (for a given election type), ordered by the date. Imagine trying to make a timetable of all the dates for a given election as a use case.abc
with abstractmethod
on the base Election
class. This will force subclasses to implement all required methodsI think this big refactoring is done now. The API has changed quite a bit.
from uk_election_timetables.election_ids import from_election_id
election = from_election_id("local.2019-02-21", country=Country.ENGLAND)
print(election.sopn_publish_date()) # date(2019, 1, 28)
A few things:
from_election_id
is basically the same as StatementPublishDate().for_id(...)
but returns an Election
instead of a specific date, so lots of room to expand this.national_assembly_for_wales
entirely - naw.*
ids now direct to SeneddCymru
elections, and we shouldn't be called the NAW specific function anywhere anyway.I'm pretty happy with this API change. Adding further dates or a .timetable()
method on Election
will be relatively easy, I think.
Next few steps:
PyPI
sopn_publish_date
with this in DC projectsIt feels like this should be a major version bump up to 2.0.0
because of the total API incompatibility with sopn_publish_date
What do you think, @symroe?
This is really good!
After checking the code out I realised I can't just run pytest
like I'd expect to, so I've pushed a commit to fix that. I've also ignored __pycache__
files.
I think the last change I'd like to see is moving sopn_publish_date
(etc) to a property rather than a method. I don't think doing election.sopn_publish_date()
makes sense when we could have election.sopn_publish_date
This looks ready to merge - sopn_publish_date
is now a property
Great stuff!
This is a proof-of-concept for how the underlying model in the library could change to adapt to the broader scope.
When the library was solely concerned with SoPN publish dates, there was a single component
StatementPublishDate
with a function for each election type.Now there are multiple interesting dates for each election type.
One way to handle this is to make the election the top-level object rather than the type of date.
This PR is an example of how we'd do that for Senedd Cymru, the Welsh Parliament. If merged, we would roll this out to all election types, which would simplify adding new dates and further election-specific logic into their own classes.