Skip to content

Commit bb529bd

Browse files
committed
feat: enforce strict CamelCase for Table names
1 parent a152006 commit bb529bd

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

datajoint/table.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ class Table(QueryExpression):
7575
def table_name(self):
7676
return self._table_name
7777

78+
@property
79+
def class_name(self):
80+
return self.__class__.__name__
81+
7882
@property
7983
def definition(self):
8084
raise NotImplementedError(
@@ -93,6 +97,14 @@ def declare(self, context=None):
9397
"Cannot declare new tables inside a transaction, "
9498
"e.g. from inside a populate/make call"
9599
)
100+
# Enforce strict CamelCase #1150
101+
if "_" in self.class_name:
102+
raise DataJointError(
103+
"Table with class name `{name}` contains an underscore. ".format(
104+
name=self.class_name
105+
) +
106+
"Classes defining tables should be formatted in strict CamelCase."
107+
)
96108
sql, external_stores = declare(self.full_table_name, self.definition, context)
97109
sql = sql.format(database=self.database)
98110
try:

tests/test_declare.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,6 @@ class Table_With_Underscores(dj.Manual):
356356
"""
357357

358358
schema_any(TableNoUnderscores)
359-
with pytest.raises(dj.DataJointError, match="CamelCase") as e:
359+
with pytest.raises(dj.DataJointError, match="strict CamelCase") as e:
360360
schema_any(Table_With_Underscores)
361361

0 commit comments

Comments
 (0)