7575 DefType ,
7676 DefTypeBase ,
7777 DefTypeClassMethod ,
78- DefTypeClassMethodArity ,
7978 DefTypeMember ,
8079 DefTypeMethod ,
8180 DefTypeMethodArity ,
82- DefTypeMethodArityBase ,
83- DefTypeMethodBase ,
8481 DefTypeProperty ,
82+ DefTypePythonMember ,
8583 DefTypeStaticMethod ,
86- DefTypeStaticMethodArity ,
8784 Do ,
8885 Fn ,
8986 FnArity ,
125122 VarRef ,
126123 Vector as VectorNode ,
127124 WithMeta ,
125+ deftype_or_reify_python_member_names ,
128126)
129127from basilisp .lang .interfaces import IMeta , IRecord , ISeq , IType , IWithMeta
130128from basilisp .lang .runtime import Var
@@ -1038,7 +1036,7 @@ def __deftype_classmethod(
10381036 method_name : str ,
10391037 args : vec .Vector ,
10401038 kwarg_support : Optional [KeywordArgSupport ] = None ,
1041- ) -> DefTypeClassMethodArity :
1039+ ) -> DefTypeClassMethod :
10421040 """Emit a node for a :classmethod member of a `deftype*` form."""
10431041 with ctx .hide_parent_symbol_table (), ctx .new_symbol_table (
10441042 method_name , is_context_boundary = True
@@ -1068,7 +1066,7 @@ def __deftype_classmethod(
10681066 )
10691067 with ctx .new_func_ctx (FunctionContext .CLASSMETHOD ), ctx .expr_pos ():
10701068 stmts , ret = _body_ast (ctx , runtime .nthrest (form , 2 ))
1071- method = DefTypeClassMethodArity (
1069+ method = DefTypeClassMethod (
10721070 form = form ,
10731071 name = method_name ,
10741072 params = vec .vector (param_nodes ),
@@ -1228,7 +1226,7 @@ def __deftype_staticmethod(
12281226 method_name : str ,
12291227 args : vec .Vector ,
12301228 kwarg_support : Optional [KeywordArgSupport ] = None ,
1231- ) -> DefTypeStaticMethodArity :
1229+ ) -> DefTypeStaticMethod :
12321230 """Emit a node for a :staticmethod member of a `deftype*` form."""
12331231 with ctx .hide_parent_symbol_table (), ctx .new_symbol_table (
12341232 method_name , is_context_boundary = True
@@ -1238,7 +1236,7 @@ def __deftype_staticmethod(
12381236 )
12391237 with ctx .new_func_ctx (FunctionContext .STATICMETHOD ), ctx .expr_pos ():
12401238 stmts , ret = _body_ast (ctx , runtime .nthrest (form , 2 ))
1241- method = DefTypeStaticMethodArity (
1239+ method = DefTypeStaticMethod (
12421240 form = form ,
12431241 name = method_name ,
12441242 params = vec .vector (param_nodes ),
@@ -1262,7 +1260,7 @@ def __deftype_staticmethod(
12621260
12631261def __deftype_or_reify_prop_or_method_arity ( # pylint: disable=too-many-branches
12641262 ctx : AnalyzerContext , form : Union [llist .List , ISeq ], special_form : sym .Symbol
1265- ) -> Union [DefTypeMethodArityBase , DefTypeProperty ]:
1263+ ) -> Union [DefTypeMethodArity , DefTypePythonMember ]:
12661264 """Emit either a `deftype*` or `reify*` property node or an arity of a `deftype*`
12671265 or `reify*` method.
12681266
@@ -1343,9 +1341,9 @@ def __deftype_or_reify_prop_or_method_arity( # pylint: disable=too-many-branche
13431341def __deftype_or_reify_method_node_from_arities ( # pylint: disable=too-many-branches
13441342 ctx : AnalyzerContext ,
13451343 form : Union [llist .List , ISeq ],
1346- arities : List [DefTypeMethodArityBase ],
1344+ arities : List [DefTypeMethodArity ],
13471345 special_form : sym .Symbol ,
1348- ) -> DefTypeMethodBase :
1346+ ) -> DefTypeMember :
13491347 """Roll all of the collected `deftype*` or `reify*` arities up into a single
13501348 method node."""
13511349 assert special_form in {SpecialForm .DEFTYPE , SpecialForm .REIFY }
@@ -1354,13 +1352,6 @@ def __deftype_or_reify_method_node_from_arities( # pylint: disable=too-many-bra
13541352 fixed_arity_for_variadic : Optional [int ] = None
13551353 num_variadic = 0
13561354 for arity in arities :
1357- if fixed_arity_for_variadic is not None :
1358- if arity .fixed_arity >= fixed_arity_for_variadic :
1359- raise AnalyzerException (
1360- f"{ special_form } method may not have a method with fixed arity "
1361- "greater than fixed arity of variadic function" ,
1362- form = arity .form ,
1363- )
13641355 if arity .is_variadic :
13651356 if num_variadic > 0 :
13661357 raise AnalyzerException (
@@ -1397,41 +1388,14 @@ def __deftype_or_reify_method_node_from_arities( # pylint: disable=too-many-bra
13971388 form = form ,
13981389 )
13991390
1400- max_fixed_arity = max (arity .fixed_arity for arity in arities )
1401-
1402- if all (isinstance (e , DefTypeMethodArity ) for e in arities ):
1403- return DefTypeMethod (
1404- form = form ,
1405- name = arities [0 ].name ,
1406- max_fixed_arity = max_fixed_arity ,
1407- arities = vec .vector (arities ), # type: ignore[arg-type]
1408- is_variadic = num_variadic == 1 ,
1409- env = ctx .get_node_env (),
1410- )
1411- elif all (isinstance (e , DefTypeClassMethodArity ) for e in arities ):
1412- return DefTypeClassMethod (
1413- form = form ,
1414- name = arities [0 ].name ,
1415- max_fixed_arity = max_fixed_arity ,
1416- arities = vec .vector (arities ), # type: ignore[arg-type]
1417- is_variadic = num_variadic == 1 ,
1418- env = ctx .get_node_env (),
1419- )
1420- elif all (isinstance (e , DefTypeStaticMethodArity ) for e in arities ):
1421- return DefTypeStaticMethod (
1422- form = form ,
1423- name = arities [0 ].name ,
1424- max_fixed_arity = max_fixed_arity ,
1425- arities = vec .vector (arities ), # type: ignore[arg-type]
1426- is_variadic = num_variadic == 1 ,
1427- env = ctx .get_node_env (),
1428- )
1429- else :
1430- raise AnalyzerException (
1431- "deftype* method arities must all be declared one of :classmethod, "
1432- ":property, :staticmethod, or none (for a standard method)" ,
1433- form = form ,
1434- )
1391+ return DefTypeMethod (
1392+ form = form ,
1393+ name = arities [0 ].name ,
1394+ max_fixed_arity = max (arity .fixed_arity for arity in arities ),
1395+ arities = vec .vector (arities ),
1396+ is_variadic = num_variadic == 1 ,
1397+ env = ctx .get_node_env (),
1398+ )
14351399
14361400
14371401def __deftype_or_reify_impls ( # pylint: disable=too-many-branches,too-many-locals # noqa: MC0001
@@ -1484,10 +1448,10 @@ def __deftype_or_reify_impls( # pylint: disable=too-many-branches,too-many-loca
14841448 # keys to act as an ordered set of members we've seen. We don't want to register
14851449 # duplicates.
14861450 member_order = {}
1487- methods : MutableMapping [
1488- str , List [ DefTypeMethodArityBase ]
1489- ] = collections . defaultdict ( list )
1490- props : MutableMapping [str , DefTypeProperty ] = {}
1451+ methods : MutableMapping [str , List [ DefTypeMethodArity ]] = collections . defaultdict (
1452+ list
1453+ )
1454+ py_members : MutableMapping [str , DefTypePythonMember ] = {}
14911455 for elem in runtime .nthrest (form , 2 ):
14921456 if not isinstance (elem , ISeq ):
14931457 raise AnalyzerException (
@@ -1497,24 +1461,29 @@ def __deftype_or_reify_impls( # pylint: disable=too-many-branches,too-many-loca
14971461
14981462 member = __deftype_or_reify_prop_or_method_arity (ctx , elem , special_form )
14991463 member_order [member .name ] = True
1500- if isinstance (member , DefTypeProperty ):
1501- if member .name in props :
1464+ if isinstance (
1465+ member , (DefTypeClassMethod , DefTypeProperty , DefTypeStaticMethod )
1466+ ):
1467+ if member .name in py_members :
15021468 raise AnalyzerException (
1503- f"{ special_form } property may only have one arity defined" ,
1469+ f"{ special_form } class methods, properties, and static methods "
1470+ "may only have one arity defined" ,
15041471 form = elem ,
15051472 lisp_ast = member ,
15061473 )
15071474 elif member .name in methods :
15081475 raise AnalyzerException (
1509- f"{ special_form } property name already defined as a method" ,
1476+ f"{ special_form } class method, property, or static method name "
1477+ "already defined as a method" ,
15101478 form = elem ,
15111479 lisp_ast = member ,
15121480 )
1513- props [member .name ] = member
1481+ py_members [member .name ] = member
15141482 else :
1515- if member .name in props :
1483+ if member .name in py_members :
15161484 raise AnalyzerException (
1517- f"{ special_form } method name already defined as a property" ,
1485+ f"{ special_form } method name already defined as a class method, "
1486+ "property, or static method" ,
15181487 form = elem ,
15191488 lisp_ast = member ,
15201489 )
@@ -1531,9 +1500,9 @@ def __deftype_or_reify_impls( # pylint: disable=too-many-branches,too-many-loca
15311500 )
15321501 continue
15331502
1534- prop = props .get (member_name )
1535- assert prop is not None , "Member must be a method or property"
1536- members .append (prop )
1503+ py_member = py_members .get (member_name )
1504+ assert py_member is not None , "Member must be a method or property"
1505+ members .append (py_member )
15371506
15381507 return interfaces , members
15391508
@@ -1557,7 +1526,7 @@ def __deftype_and_reify_impls_are_all_abstract( # pylint: disable=too-many-bran
15571526 assert special_form in {SpecialForm .DEFTYPE , SpecialForm .REIFY }
15581527
15591528 field_names = frozenset (fields )
1560- member_names = frozenset (munge ( member . name ) for member in members )
1529+ member_names = frozenset (deftype_or_reify_python_member_names ( members ) )
15611530 all_member_names = field_names .union (member_names )
15621531 all_interface_methods : Set [str ] = set ()
15631532 for interface in interfaces :
@@ -1916,13 +1885,6 @@ def _fn_ast( # pylint: disable=too-many-branches
19161885 fixed_arity_for_variadic : Optional [int ] = None
19171886 num_variadic = 0
19181887 for arity in arities :
1919- if fixed_arity_for_variadic is not None :
1920- if arity .fixed_arity >= fixed_arity_for_variadic :
1921- raise AnalyzerException (
1922- "fn may not have a method with fixed arity greater than "
1923- "fixed arity of variadic function" ,
1924- form = arity .form ,
1925- )
19261888 if arity .is_variadic :
19271889 if num_variadic > 0 :
19281890 raise AnalyzerException (
0 commit comments