Skip to content

Commit 14f7b60

Browse files
committed
default kwargs are evaluated at definition time
This stackoverflow question covers the topic pretty well: http://stackoverflow.com/q/1132941/1547030 From docs.python.org: Default parameter values are evaluated when the function definition is executed. This means that the expression is evaluated once, when the function is defined, and that the same “pre-computed” value is used for each call. This is especially important to understand when a default parameter is a mutable object, such as a list or a dictionary: if the function modifies the object (e.g. by appending an item to a list), the default value is in effect modified. This is generally not what was intended. A way around this is to use None as the default, and explicitly test for it in the body of the function
1 parent dfc8fa0 commit 14f7b60

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

pythonwhois/net.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
from codecs import encode, decode
33
from . import shared
44

5-
def get_whois_raw(domain, server="", previous=[], rfc3490=True, never_cut=False, with_server_list=False, server_list=[]):
5+
def get_whois_raw(domain, server="", previous=None, rfc3490=True, never_cut=False, with_server_list=False, server_list=None):
6+
previous = previous or []
7+
server_list = server_list or []
68
# Sometimes IANA simply won't give us the right root WHOIS server
79
exceptions = {
810
".ac.uk": "whois.ja.net",
@@ -20,7 +22,6 @@ def get_whois_raw(domain, server="", previous=[], rfc3490=True, never_cut=False,
2022

2123
if len(previous) == 0 and server == "":
2224
# Root query
23-
server_list = [] # Otherwise it retains the list on subsequent queries, for some reason.
2425
is_exception = False
2526
for exception, exc_serv in exceptions.items():
2627
if domain.endswith(exception):

pythonwhois/parse.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,8 @@ def is_string(data):
426426
return isinstance(data, str)
427427

428428

429-
def parse_raw_whois(raw_data, normalized=[], never_query_handles=True, handle_server=""):
429+
def parse_raw_whois(raw_data, normalized=None, never_query_handles=True, handle_server=""):
430+
normalized = normalized or []
430431
data = {}
431432

432433
raw_data = [segment.replace("\r", "") for segment in raw_data] # Carriage returns are the devil
@@ -995,4 +996,4 @@ def parse_nic_contact(data):
995996
for match in matches:
996997
handle_contacts.append(match.groupdict())
997998

998-
return handle_contacts
999+
return handle_contacts

0 commit comments

Comments
 (0)