Python Mutable References with Caching

So, while working with caching and scrapping, I understood the difference between immutable and mutable objects/datatypes very clearly. I had a scenario, where I am webscraping an API, the code looks like this. from aiocache import cached @cached(ttl=7200) async def get_forecast(station_id: str) -> list[dict]: data: dict = await scrape_weather(station_id) # doing some operation return forecasts and then using this utility tool in the endpoint. async def get_forecast_by_city( param: Annotated[StationIDQuery, Query()], ) -> list[UpcomingForecast]: forecasts_dict: list[dict] = await get_forecast(param.station_id) forecasts_dict.reversed() forecasts: deque[UpcomingForecast] = deque([]) for forecast in forecasts_dict: date_delta: int = ( date.fromisoformat(forecast["forecast_date"]) - date.today() ).days if date_delta <= 0: break forecasts.appendleft(UpcomingForecast.model_validate(forecast)) return list(forecasts) But, here is the gotcha, something I was doing inherently wrong. Lists in python are mutable objects. So, reversing the list modifies the list in place, without creating a new reference of the list. My initial approach was to do this ...

February 15, 2026 · 2 min

Snapcraft: Adopting appstream metadata

Introduction Whatever takes time takes for good. Yeah, so, about on March I created a PR on snapcraft by canonical. It was about adopting more metadata from the parsed appstrean metadata file. The new fields that were made to parse were License Contact Issues Source Code (VCS Browser) Website Donation Link What does this change means? For publishers/snapcrafters Publishers and snapcrafters who also maintains an appstrean metadata for their app, you don’t need to maintain the metadata in your snap package separately. Just add the metadata file in your snap and you’re good to go. (Also please keep in mind to enable the update metadata from snapcraft option in case you disabled it). ...

May 31, 2024 · 3 min