[fix] handling None return values e.g. for languages with no configs yet
This commit is contained in:
@@ -23,6 +23,8 @@ class Entrance(NumberedComponent):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def random(cls, language, country=None):
|
def random(cls, language, country=None):
|
||||||
num_type, num_type_props = cls.choose_alphanumeric_type('entrances.alphanumeric', language, country=country)
|
num_type, num_type_props = cls.choose_alphanumeric_type('entrances.alphanumeric', language, country=country)
|
||||||
|
if num_type is None:
|
||||||
|
return None
|
||||||
|
|
||||||
if num_type == cls.NUMERIC:
|
if num_type == cls.NUMERIC:
|
||||||
number = weighted_choice(cls.entrance_range, cls.entrance_range_cdf)
|
number = weighted_choice(cls.entrance_range, cls.entrance_range_cdf)
|
||||||
|
|||||||
@@ -38,6 +38,8 @@ class Floor(NumberedComponent):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def random(cls, language, country=None, num_floors=None, num_basements=None):
|
def random(cls, language, country=None, num_floors=None, num_basements=None):
|
||||||
num_type, num_type_props = cls.choose_alphanumeric_type('levels.alphanumeric', language, country=country)
|
num_type, num_type_props = cls.choose_alphanumeric_type('levels.alphanumeric', language, country=country)
|
||||||
|
if num_type is None:
|
||||||
|
return None
|
||||||
|
|
||||||
if num_floors is not None:
|
if num_floors is not None:
|
||||||
number = cls.sample_floors(num_floors, num_basements or 0)
|
number = cls.sample_floors(num_floors, num_basements or 0)
|
||||||
|
|||||||
@@ -116,7 +116,9 @@ class NumberedComponent(object):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def choose_alphanumeric_type(cls, key, language, country=None):
|
def choose_alphanumeric_type(cls, key, language, country=None):
|
||||||
alphanumeric_props = address_config.get_property(key, language, country=country)
|
alphanumeric_props = address_config.get_property(key, language, country=country, default=None)
|
||||||
|
if alphanumeric_props is None:
|
||||||
|
return None, None
|
||||||
|
|
||||||
values = []
|
values = []
|
||||||
probs = []
|
probs = []
|
||||||
|
|||||||
@@ -33,6 +33,8 @@ class POBox(NumberedComponent):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def random(cls, language, country=None):
|
def random(cls, language, country=None):
|
||||||
num_type, num_type_props = cls.choose_alphanumeric_type('po_boxes.alphanumeric', language, country=country)
|
num_type, num_type_props = cls.choose_alphanumeric_type('po_boxes.alphanumeric', language, country=country)
|
||||||
|
if num_type is None:
|
||||||
|
return None
|
||||||
|
|
||||||
if num_type != cls.ALPHA:
|
if num_type != cls.ALPHA:
|
||||||
digit_config = address_config.get_property('po_boxes.digits', language, country=country, default=[])
|
digit_config = address_config.get_property('po_boxes.digits', language, country=country, default=[])
|
||||||
@@ -66,5 +68,7 @@ class POBox(NumberedComponent):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def phrase(cls, box_number, language, country=None):
|
def phrase(cls, box_number, language, country=None):
|
||||||
|
if box_number is None:
|
||||||
|
return None
|
||||||
return cls.numeric_phrase('po_boxes.alphanumeric', safe_decode(box_number), language,
|
return cls.numeric_phrase('po_boxes.alphanumeric', safe_decode(box_number), language,
|
||||||
dictionaries=['post_office'], country=country)
|
dictionaries=['post_office'], country=country)
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ class Staircase(NumberedComponent):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def random(cls, language, country=None):
|
def random(cls, language, country=None):
|
||||||
num_type, num_type_props = cls.choose_alphanumeric_type('staircases.alphanumeric', language, country=country)
|
num_type, num_type_props = cls.choose_alphanumeric_type('staircases.alphanumeric', language, country=country)
|
||||||
|
if num_type is None:
|
||||||
|
return None
|
||||||
|
|
||||||
if num_type == cls.NUMERIC:
|
if num_type == cls.NUMERIC:
|
||||||
number = weighted_choice(cls.staircase_range, cls.staircase_range_cdf)
|
number = weighted_choice(cls.staircase_range, cls.staircase_range_cdf)
|
||||||
|
|||||||
@@ -52,6 +52,8 @@ class Unit(NumberedComponent):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def random(cls, language, country=None, num_floors=None, num_basements=None):
|
def random(cls, language, country=None, num_floors=None, num_basements=None):
|
||||||
num_type, num_type_props = cls.choose_alphanumeric_type('units.alphanumeric', language, country=country)
|
num_type, num_type_props = cls.choose_alphanumeric_type('units.alphanumeric', language, country=country)
|
||||||
|
if num_type is None:
|
||||||
|
return None
|
||||||
|
|
||||||
use_floor_prob = address_config.get_property('units.alphanumeric.use_floor_probability', language, country=country, default=0.0)
|
use_floor_prob = address_config.get_property('units.alphanumeric.use_floor_probability', language, country=country, default=0.0)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user