|
26 | 26 | from .heading import Heading |
27 | 27 | from .settings import config |
28 | 28 | from .staged_insert import staged_insert1 as _staged_insert1 |
29 | | -from .utils import get_master, is_camel_case, user_choice |
| 29 | +from .utils import get_master, is_camel_case, is_valid_class_name, user_choice |
30 | 30 |
|
31 | 31 | logger = logging.getLogger(__name__.split(".")[0]) |
32 | 32 |
|
@@ -151,11 +151,19 @@ def declare(self, context=None): |
151 | 151 | """ |
152 | 152 | if self.connection.in_transaction: |
153 | 153 | raise DataJointError("Cannot declare new tables inside a transaction, e.g. from inside a populate/make call") |
154 | | - # Enforce strict CamelCase #1150 |
155 | | - if not is_camel_case(self.class_name): |
| 154 | + # Validate class name #1150 |
| 155 | + if not is_valid_class_name(self.class_name): |
156 | 156 | raise DataJointError( |
157 | | - "Table class name `{name}` is invalid. Please use CamelCase. ".format(name=self.class_name) |
158 | | - + "Classes defining tables should be formatted in strict CamelCase." |
| 157 | + f"Table class name `{self.class_name}` is invalid. " |
| 158 | + "Class names must start with a capital letter and contain only " |
| 159 | + "alphanumeric characters (underscores allowed for legacy support)." |
| 160 | + ) |
| 161 | + if not is_camel_case(self.class_name): |
| 162 | + warnings.warn( |
| 163 | + f"Table class name `{self.class_name}` contains underscores. " |
| 164 | + "CamelCase names without underscores are recommended.", |
| 165 | + UserWarning, |
| 166 | + stacklevel=2, |
159 | 167 | ) |
160 | 168 | sql, _external_stores, primary_key, fk_attribute_map = declare(self.full_table_name, self.definition, context) |
161 | 169 |
|
|
0 commit comments