terrencepreilly / darglint

A python documentation linter which checks that the docstring description matches the definition.
MIT License
481 stars 41 forks source link

Feature: allows ast subscript #194

Closed lucasiscovici2 closed 2 years ago

lucasiscovici2 commented 2 years ago

Hello, and thank you for dev Darglint 🙂 This Pr is intended to allow more complicated types hints to be detected for parameters and return. (With "[") Ex: List[int], Union[int, str], ....

TODO :

Explanation :

Why ast.parse/ast.dump ?

Pb ?

Alternatives :

Even if it's a draft, I would like your corrections/comments ✍🏻 🙂

Ex: test.py

def fib(self, a: List[int], b: int) -> List[int]:
        """Fibo.

        Parameters
        ----------
        a : List[str]
            the first number
        b : int
            the second number

        Returns
        -------
        List[int]
            the fibo resut
        """
        return a
original_darglint test.py  // no error
darglint test.py  // test.py:fib:0: DAR103:  ~a: expected Subscript(Name('List', Load()), Name('int', Load()), Load()) but was List[str]
terrencepreilly commented 2 years ago

Could you explain what problem this PR is solving? How is doing analysis on the function's type signature helpful? Ideally, an explanation for why this is useful would include examples, a brief cost-benefit analysis (e.g. how difficult would this change be to maintain), and an explanation of alternative solutions.

lucasiscovici2 commented 2 years ago

Could you explain what problem this PR is solving? How is doing analysis on the function's type signature helpful? Ideally, an explanation for why this is useful would include examples, a brief cost-benefit analysis (e.g. how difficult would this change be to maintain), and an explanation of alternative solutions.

@terrencepreilly https://github.com/terrencepreilly/darglint/pull/194#issue-1106148726

lucasiscovici2 commented 2 years ago

@terrencepreilly maybe the best is to use astunparse (Until python 3.8) and ast.unparse (From python 3.9) ?

lucasiscovici2 commented 2 years ago

@terrencepreilly maybe the best is to use astunparse (Until python 3.8) and ast.unparse (From python 3.9) ?

@terrencepreilly i create the pr #195 for this solution 🙂