File tree Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Original file line number Diff line number Diff line change 9
9
import functools
10
10
import importlib .util
11
11
from toposort import toposort_flatten
12
+ import inflection
12
13
13
14
14
15
class Error (Exception ):
@@ -210,8 +211,12 @@ def modify(self, prop: Property):
210
211
def _get_class (cls : type ) -> Class :
211
212
if not isinstance (cls , type ):
212
213
raise Error (f"Only class definitions allowed in schema, found { cls } " )
213
- if cls .__name__ [0 ].islower ():
214
- raise Error (f"Class name must be capitalized, found { cls .__name__ } " )
214
+ # we must check that going to dbscheme names and back is preserved
215
+ # In particular this will not happen if uppercase acronyms are included in the name
216
+ to_underscore_and_back = inflection .camelize (inflection .underscore (cls .__name__ ), uppercase_first_letter = True )
217
+ if cls .__name__ != to_underscore_and_back :
218
+ raise Error (f"Class name must be upper camel-case, without capitalized acronyms, found { cls .__name__ } "
219
+ f"instead of { to_underscore_and_back } " )
215
220
if len ({b ._group for b in cls .__bases__ if hasattr (b , "_group" )}) > 1 :
216
221
raise Error (f"Bases with mixed groups for { cls .__name__ } " )
217
222
if any (getattr (b , "_null" , False ) for b in cls .__bases__ ):
Original file line number Diff line number Diff line change @@ -669,5 +669,16 @@ class Null2(Root):
669
669
pass
670
670
671
671
672
+ def test_uppercase_acronyms_are_rejected ():
673
+ with pytest .raises (schema .Error ):
674
+ @schema .load
675
+ class data :
676
+ class Root :
677
+ pass
678
+
679
+ class ROTFLNode (Root ):
680
+ pass
681
+
682
+
672
683
if __name__ == '__main__' :
673
684
sys .exit (pytest .main ([__file__ ] + sys .argv [1 :]))
You can’t perform that action at this time.
0 commit comments