Giter VIP home page Giter VIP logo

make-stub-files's People

Contributors

boxed avatar cvzi avatar edreamleo avatar sdsmith avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

make-stub-files's Issues

Creates duplicate annotations for function arguments that are already annotated

Input:

class UnsupportedAlgorithm(Exception):
    def __init__(self, message: Any, reason: Optional[str]=None) -> None:

Output:

class UnsupportedAlgorithm(Exception):
    def __init__(self, message: Any: Any, reason: Optional[str]: Any=None) -> None: ...

Expected output:

class UnsupportedAlgorithm(Exception):
    def __init__(self, message: Any, reason: Optional[str]=None) -> None: ...

More aggressive type inference

reduce_types: computes that c.canMoveOutlineRight returns Union[Any, Union[Any, bool]].

def canMoveOutlineLeft(self):
    c = self; p = c.p
    if c.hoistStack:
        bunch = c.hoistStack[-1]
        if p and p.hasParent():
            p.moveToParent()
            return p != bunch.p and bunch.p.isAncestorOf(p)
        return False
    return p and p.hasParent()

In fact, for this method, the intended type is, bool, even though the expression:

p and p.hasParent()

might return None in addition to True or False. It's not clear that this "extension" of bool is possible, or even desirable, but I'll give it a try. I would rather not write:

return bool(p and p.hasParent())

just to give make the return type explicit.

Hmm. I wonder what mypy itself uses for the effective type of this function.

One unit tests fails

This test failed before revising tests.

> python -m unittest discover test

FAIL: runTest (test_bug3.test_bug3)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "...test\test_bug3.py", line 22, in runTest
    assert got == expected, '\nexpected:\n%s\ngot:\n%s' % (expected, got)
AssertionError:
expected:
class UnsupportedAlgorithm(Exception):
    def __init__(self, message: Any, reason: Optional[str]=None) -> None: ...

got:
class UnsupportedAlgorithm(Exception):
    def __init__(self, message: Any, reason: Optional[str]=) -> None: ...

Use traditional unit tests with full coverage

Using proper unit tests instead of @test nodes is considerably simpler, and will allow coverage testing with py-cov.
The following Leonine script coverts @test tests nodes to nodes containing traditional unit tests.

"""Convert all following @test nodes."""
g.cls()

def body(p):
    def_s = f"def {headline(p)}(self):\n"
    lines = [' '*4 + z.rstrip()+'\n' for z in g.splitLines(p.b) if '@others' not in z]
    return def_s + ''.join(lines)

def headline(p):
    return p.h[1:].replace('-','_').replace(' ','_').replace('__', '_')

while p:
    if p.h.startswith('@test'):
        if 1:  # Change.
            print(p.h)
            p.b = body(p)  # body first, to use original headline.
            p.h = headline(p)
            p.setDirty()
        else:  # Report.
            h = headline(p)
            b = body(p)
            print(h.rstrip())
            print(b.rstrip())
            print('-'*40)
    p.moveToThreadNext()
c.redraw()

Fails to generate valid stubs for empty classes

An empty class will exist in the generated stub file; but will not have anything as the body of the class meaning the stub is invalid.

Input:

class InvalidTag(Exception):
    pass

Output:

class InvalidTag(Exception):

Expected Output:

class InvalidTag(Exception): ...

Fail if output_directory is '.'

I just get the error message not found: (without anything following). This seems because os.path.exists('') is false, and this is because dir_ is empty. That in turn is because normpath('./foo') returns 'foo', and then dirname() returns ''.

So the fix is to add "or not dir_" to line 1180.

[question] producing docstring/help

Thank you for sharing this repo. I'm using the script to produce a stub for pylance in python extension of visual studio code.
It works as expected but, if possible, I'd love to add the documentation to the stub.
For example currently I have
def delete_where(server: Any, database: Any, table: Any, where_clause: Any, where_params: Any) -> None: ...
Is there a way to produce also the following doc string so that pylance can see it?

def delete_where(server: Any, database: Any, table: Any, where_clause: Any, where_params: Any) -> None:
    """Deletes records from a table.

    Args:
        server (str): the server in the conn string.
        database (str): the database in the conn string.
        where_clause (str): for example 'WHERE my_field=?': use qmark.
        database (list): the list of values for the parameters in the where clause.

    Returns:
        None.
    """

I could manually add it in the *.pyi but then I guess I would lose it when I want to update it with a new script run, correct? Any tips? Thank you anyway.

Edit

Another quick question:
is there a way to make it accept a .pyx file as a normal python input instead of having to rename it as .py all the times I want to regenerate the stub?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.