edreamleo / make-stub-files Goto Github PK
View Code? Open in Web Editor NEWScript and config file that creates python stub (.pyi) files
License: Other
Script and config file that creates python stub (.pyi) files
License: Other
I plan no further work on this project, except to fix bugs.
Only a few sections needed updating.
is there any command to download the package?
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: ...
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.
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: ...
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()
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): ...
Traces do not show None properly, nor do stubs.
I fixed this by adding a node
argument to format_return_expressions
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.
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?
The data should reside in the respective issues.
I worked around this by changing AstFormatter.visit
to catch the AttributeError it produces with the line method = getattr(self, method_name)
and just return empty string.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.