Skip to content

Commit

Permalink
tld: fix assigning a dict to an attribute originally defined as a list
Browse files Browse the repository at this point in the history
New type-hinted parser attribute to store the parsed data instead, and
delete the temporary value used during parsing.

Said new type hint isn't doing much work yet since the code that
eventually assigns to the new attribute isn't hinted, but I don't want
to change too much in this particular branch; we're ONLY worried about
actual mypy errors right now. Hinting more stuff for real comes later.
  • Loading branch information
dgw committed Jun 21, 2023
1 parent 99ad38f commit 3ffe55c
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions sopel/modules/tld.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from html.parser import HTMLParser
import logging
import re
from typing import Dict

import pytz
import requests
Expand Down Expand Up @@ -100,6 +101,7 @@ def __init__(self):
self.current_cell = ''
self.rows = []
self.tables = []
self.parsed: Dict[str, Dict[str, str]] = {}
self.finished = False

def handle_starttag(self, tag, attrs):
Expand Down Expand Up @@ -158,7 +160,7 @@ def get_processed_data(self):
LOGGER.debug("Processed TLD data requested.")
if self.finished:
LOGGER.debug("Returning stored previously-processed data.")
return self.tables
return self.parsed

LOGGER.debug("Ensuring all buffered data has been parsed.")
self.close()
Expand Down Expand Up @@ -202,8 +204,12 @@ def get_processed_data(self):
tld_list[idn_key] = zipped

LOGGER.debug("Finished processing TLD data; returning it.")
self.tables = tld_list
self.finished = True
# clear working data
del self.tables
# cache parsed data for future requests to this parser
self.parsed = tld_list

return self.tables

This comment has been minimized.

Copy link
@dgw

dgw Jul 12, 2023

Author Member

This line is a bug that got merged to mainline, sorry. Messed up my bisect today trying to track down another issue. 😅



Expand Down

0 comments on commit 3ffe55c

Please sign in to comment.