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
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.
Thank You
The text was updated successfully, but these errors were encountered:
OmarAlJarrah
changed the title
GoogleDocstrings: Issue Parsing constr with regex as Attributes.
GoogleDocstrings: Issue Parsing constr with regex inside Attributes Section.
Mar 31, 2023
Description
When an attribute in the docstrings has a
constr
in its type hint, with a regex as a constraint, the splitting of type and description is not correct.Consider the following docstring:
If we take a look on how splitting of description and anything that comes before it, it happens as follows (in
google.py
, line115
):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 ifregex=
is present in thebefore
part, and validate wether the type hint in thebefore
part is actually a valid type hint, usingast
,astor
andastvalidate
, 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 aCallable
, and a list offixers
, where each fixer is aCallable
thatattemps_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.Thank You
The text was updated successfully, but these errors were encountered: