Skip to content

Commit 048bf86

Browse files
authored
Fixed issue with incorrect warning on class names (#236)
For classes named with a reserved word (like arguments), we would print an incorrect warning.
1 parent a86ae64 commit 048bf86

File tree

5 files changed

+50
-4
lines changed

5 files changed

+50
-4
lines changed

CHANGES.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
sphinxcontrib-matlabdomain-0.21.X (2024-MM-DD)
2+
==============================================
3+
4+
* Fixed issue with warning if there is a mismatch between filename and
5+
classname, if the classname is a reserved word (like arguments).
6+
7+
18
sphinxcontrib-matlabdomain-0.21.3 (2024-01-02)
29
==============================================
310

sphinxcontrib/mat_types.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,10 +1055,10 @@ def __init__(self, name, modname, tokens):
10551055

10561056
# class "attributes"
10571057
self.attrs, idx = self.attributes(idx, MATLAB_CLASS_ATTRIBUTE_TYPES)
1058-
# =====================================================================
1059-
# classname
1060-
idx += self._blanks(idx) # skip blanks
1061-
if self._tk_ne(idx, (Token.Name, self.name)):
1058+
1059+
# Check if self.name matches the name in the file.
1060+
idx += self._blanks(idx)
1061+
if not self.tokens[idx][1] == self.name:
10621062
logger.warning(
10631063
"[sphinxcontrib-matlabdomain] Unexpected class name: '%s'."
10641064
" Expected '%s' in '%s'.",

tests/test_data/arguments.m

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
classdef arguments < handle & matlab.mixin.Copyable
2+
%ARGUMENTS Aggregate arguments for later
3+
4+
properties (SetAccess=private, GetAccess=public)
5+
value
6+
end
7+
8+
methods
9+
function obj = arguments()
10+
% Constructor for arguments
11+
obj.value = {};
12+
end
13+
function add(obj, foo)
14+
% Add new argument
15+
if isa(foo, 'arguments')
16+
for i = 1:length(foo.value)
17+
obj.value{end+1} = foo.value{i};
18+
end
19+
else
20+
obj.value{end+1} = foo;
21+
end
22+
end
23+
24+
end
25+
26+
end

tests/test_matlabify.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ def test_module(mod):
117117
"ClassWithTrailingSemicolons",
118118
"ClassWithSeperatedComments",
119119
"ClassWithKeywordsAsFieldnames",
120+
"arguments",
120121
}
121122
assert all_items == expected_items
122123
assert mod.getter("__name__") in entities_table

tests/test_parse_mfile.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -872,5 +872,17 @@ def test_ClassWithKeywordsAsFieldnames():
872872
assert meth.docstring == " Returns the value of `d`\n"
873873

874874

875+
def test_ClassWithNamedAsArguments():
876+
mfile = os.path.join(TESTDATA_ROOT, "arguments.m")
877+
obj = mat_types.MatObject.parse_mfile(mfile, "arguments", "test_data")
878+
assert obj.name == "arguments"
879+
assert obj.bases == ["handle", "matlab.mixin.Copyable"]
880+
assert "value" in obj.properties
881+
meth = obj.methods["arguments"]
882+
assert meth.docstring == " Constructor for arguments\n"
883+
meth = obj.methods["add"]
884+
assert meth.docstring == " Add new argument\n"
885+
886+
875887
if __name__ == "__main__":
876888
pytest.main([os.path.abspath(__file__)])

0 commit comments

Comments
 (0)