You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
GoogleDocstrings: Issue Parsing constr with regex inside Attributes Section. #76
If we take a look on how splitting of description and anything that comes before it, it happens as follows (in google.py, line 115):
# Split spec and descriptionbefore, desc=text.split(":", 1)
As we can see, we are splitting depending on the first colon : that occurs in the string, which results in the issue, given the first occurrence of a colon is in the regex.
Suggestions
I have suffered from the issue, then I started developing a solution to properly cover this edge case, it is very simple considering the issue itself is not.
Solution
Adding a simple if-statement, to check if regex= is present in the before part, and validate wether the type hint in the before part is actually a valid type hint, using ast, astor and astvalidate, building a type hint ast node, and validating its integrity, then using some regexes to do a further better parsing if needed, and solve the problem.
Far More Improvement:
Consider the previous solution as a solution to the problem we have, I think having a set of Validator objects, where each object is just a wrapper around a Callable, and a list of fixers, where each fixer is a Callable that attemps_fix the issue for it's wrapper validator, would help solve as many similar issues as possible, without the need to mess up the code.
Final Words
Developing the Far More Improved version would take time and effort, plus few discussions to agree on the design of such solution, such that it works properly for all parsers, for now I suggest we simply go ahead and solve the issue, if we agree here, I can push a PR to fix the problem, as I have already developed the solution locally.
changed the title [-]GoogleDocstrings: Issue Parsing `constr` with `regex` as Attributes.[/-][+]GoogleDocstrings: Issue Parsing `constr` with `regex` inside Attributes Section.[/+]on Mar 31, 2023
Thanks for the detailed report and for digging into the cause. The Google parser now finds the colon that ends an item's head outside brackets (#184), so the Optional[constr(..., regex=r'...')] attribute comes back with the whole type, is_optional set and description. as its text.
Activity
[-]GoogleDocstrings: Issue Parsing `constr` with `regex` as Attributes.[/-][+]GoogleDocstrings: Issue Parsing `constr` with `regex` inside Attributes Section.[/+]rr- commentedon Nov 7, 2026
Thanks for the detailed report and for digging into the cause. The Google parser now finds the colon that ends an item's head outside brackets (#184), so the
Optional[constr(..., regex=r'...')]attribute comes back with the whole type,is_optionalset anddescription.as its text.