From 62ceca67a32bffc3dcacec4653a5c04c7f398102 Mon Sep 17 00:00:00 2001 From: Austin Weisgrau Date: Mon, 5 Feb 2024 14:04:43 -0800 Subject: [PATCH] Allow Table(None) --- parsons/etl/table.py | 24 ++---------------------- test/test_etl.py | 5 ++--- 2 files changed, 4 insertions(+), 25 deletions(-) diff --git a/parsons/etl/table.py b/parsons/etl/table.py index 28a6b6cd0..edbdfa316 100644 --- a/parsons/etl/table.py +++ b/parsons/etl/table.py @@ -1,6 +1,5 @@ import logging import pickle -from enum import Enum from typing import Union import petl @@ -14,20 +13,6 @@ DIRECT_INDEX_WARNING_COUNT = 10 -class _EmptyDefault(Enum): - """Default argument for Table() - - This is used because Table(None) should not be allowed, but we - need a default argument that isn't the mutable [] - - See https://stackoverflow.com/a/76606310 for discussion.""" - - token = 0 - - -_EMPTYDEFAULT = _EmptyDefault.token - - class Table(ETL, ToFrom): """ Create a Parsons Table. Accepts one of the following: @@ -46,16 +31,11 @@ class Table(ETL, ToFrom): def __init__( self, - lst: Union[list, tuple, petl.util.base.Table, _EmptyDefault] = _EMPTYDEFAULT, + lst: Union[list, tuple, petl.util.base.Table, None] = None, ): self.table = None - # Normally we would use None as the default argument here - # Instead of using None, we use a sentinal - # This allows us to maintain the existing behavior - # This is allowed: Table() - # This should fail: Table(None) - if lst is _EMPTYDEFAULT: + if lst is None: self.table = petl.fromdicts([]) elif isinstance(lst, list) or isinstance(lst, tuple): diff --git a/test/test_etl.py b/test/test_etl.py index 89d8598ab..fa8e0dad0 100644 --- a/test/test_etl.py +++ b/test/test_etl.py @@ -67,9 +67,8 @@ def test_from_invalid_list(self): self.assertRaises(ValueError, Table, list_of_invalid) def test_from_empty_petl(self): - # This test ensures that this would fail: Table(None) - # Even while allowing Table() to work - self.assertRaises(ValueError, Table, None) + # Just ensure this doesn't throw an error + Table(None) def test_from_empty_list(self): # Just ensure this doesn't throw an error