Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a contrib module to generate type hints for capnp schemas #260

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

gjcarneiro
Copy link

Hello. I wrote a python module to generate python type hints for capnp schema modules.

I have done some testing on it, with a private code base. It probably isn't complete. Most notably, I haven't written support for interfaces (have not needed them yet).

I thought you could include it as a contrib module, to be invoked thus: python -m capnp.contrib.genpyi ....

Even if not complete, I think it can be useful already. At least I am finding it useful on my code bases...

@lgtm-com
Copy link

lgtm-com bot commented May 18, 2021

This pull request introduces 5 alerts when merging 6cb558c into 581332f - view on LGTM.com

new alerts:

  • 3 for Unused import
  • 2 for Unused local variable

@lgtm-com
Copy link

lgtm-com bot commented May 18, 2021

This pull request introduces 1 alert when merging 9166a49 into 581332f - view on LGTM.com

new alerts:

  • 1 for Unused import

@jayvdb
Copy link
Contributor

jayvdb commented May 31, 2021

> pyflakes capnp/contrib/genpyi.py
capnp/contrib/genpyi.py:98:23 undefined name 'Set'
capnp/contrib/genpyi.py:99:30 undefined name 'Set'
capnp/contrib/genpyi.py:278:13 import 'field' from line 24 shadowed by loop variable
capnp/contrib/genpyi.py:322:21 local variable 'ex' is assigned to but never used
capnp/contrib/genpyi.py:329:21 local variable 'ex' is assigned to but never used
capnp/contrib/genpyi.py:360:17 local variable 'ex' is assigned to but never used
capnp/contrib/genpyi.py:400:20 f-string is missing placeholders
capnp/contrib/genpyi.py:402:20 f-string is missing placeholders

@haata
Copy link
Collaborator

haata commented Aug 25, 2021

I'm definitely interested in including this, but please fix the warnings and errors first.

@lgtm-com
Copy link

lgtm-com bot commented Oct 1, 2021

This pull request introduces 1 alert when merging 574eb05 into 5dade41 - view on LGTM.com

new alerts:

  • 1 for Unused import

@haata
Copy link
Collaborator

haata commented Oct 1, 2021

Closer, but still seeing some linting errors

 ./capnp/contrib/genpyi.py:133:52: E203 whitespace before ':'
                schema.node.displayNamePrefixLength :
                                                   ^
./capnp/contrib/genpyi.py:187:5: C901 'Writer.type_ref' is too complex (11)
    def type_ref(self, type_node) -> str:
    ^
./capnp/contrib/genpyi.py:227:17: W503 line break before binary operator
                + ", ".join(imp for imp in sorted(self.typing_imports))
                ^
./capnp/contrib/genpyi.py:242:71: E203 whitespace before ':'
    name = schema.node.displayName[schema.node.displayNamePrefixLength :]
                                                                      ^
./capnp/contrib/genpyi.py:252:71: E203 whitespace before ':'
    name = schema.node.displayName[schema.node.displayNamePrefixLength :]
                                                                      ^
./capnp/contrib/genpyi.py:265:1: C901 'gen_struct' is too complex (35)
def gen_struct(schema, writer, name: str = ""):
^
./capnp/contrib/genpyi.py:272:75: E203 whitespace before ':'
        name = schema.node.displayName[schema.node.displayNamePrefixLength :]
                                                                          ^
./capnp/contrib/genpyi.py:283:17: W503 line break before binary operator
                and field.slot.type.anyPointer.which() == "parameter"
                ^
2     C901 'Writer.type_ref' is too complex (11)
4     E203 whitespace before ':'
2     W503 line break before binary operator

@gjcarneiro
Copy link
Author

Hm, can you tell me the command to check those?

To be honest, I just format with black. How quaint that this project wants a formatting style not compatible with black..

@haata
Copy link
Collaborator

haata commented Oct 1, 2021

I've started using black for some other projects (I quite like it actually). I'll do some experimentation to see how much it changes pycapnp (losing git blame history is a bit of a pain).

flake8 . --filename '*.py,*.pyx,*.pxd' --count --max-complexity=10 --max-line-length=120 --ignore=E211,E225,E226,E227,E231,E251,E261,E262,E265,E402,E999 --show-source --statistics --exclude benchmark,build,capnp/templates/module.pyx

flake8 . --count --max-complexity=10 --max-line-length=120 --show-source --statistics --exclude benchmark,build

@haata
Copy link
Collaborator

haata commented Oct 1, 2021

I think I've found the issue, I'll be updating the flake8 configuration shortly.

@haata
Copy link
Collaborator

haata commented Oct 4, 2021

@gjcarneiro can you rebase your commit to master? It should hopefully pass now.

@lgtm-com
Copy link

lgtm-com bot commented Oct 4, 2021

This pull request introduces 1 alert when merging b310447 into 6e7fffd - view on LGTM.com

new alerts:

  • 1 for Unused import

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants