-
Notifications
You must be signed in to change notification settings - Fork 81
The global___ name mangling breaks my type check #116
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
Comments
Hi I believe this is the commit which added the This commit added mangling to fix a field name / message name aliasing issue #108 I believe the The mangled name should be an implementation detail - implementing an option to disable name-mangling doesn't make sense here. The original name should also be exposed Do you have an example of a generated Thanks for the report! Here's an example generated file from the testsuite. As you can see, both TestMessage and global__TestMessage should be exposed.
|
Sorry about the delay in response! Times are a bit crazy. Hope you're doing well! |
I was able to find your proto file by digging around https://github.com/ripple/rippled/blob/develop/src/ripple/proto/org/xrpl/rpc/v1/ledger.proto In your link, seeing an error like
At first, I thought it might have to do with some interaction between inner enums and oneofs, so I added some tests (#122) - but those seemed to work ok. I copied the entire I suspect that the mangling is a red herring and doesn't have anything to do with the issue you're facing. Something else is going on. If you're able to open up your |
Is it possible that you have two different versions of mypy-protobuf running? Where the pyi files were generated by one version and being referenced by another version? |
That could be possible. I tried revisiting this issue over the weekend and wasn't able to reproduce it any more. To be honest, I'm prepared to just let it go. If I figure out how to reproduce it again (by accident because I won't be dedicating any deliberate effort), then I'll re-open this issue. Thanks for taking a look. |
The problem this fixed may have been caused by a misconfigured environment. See: nipunn1313/mypy-protobuf#116
According to my
Seems just about impossible that I would have two different versions of mypy-protobuf running. There's only one virtual environment in my project directory, which Poetry uses, and my pyenv installation has never installed mypy-protobuf, so there is no shim for it. Here is another demonstration of the errors. Here is how I reproduce these errors on my machine:
The first error from mypy is this:
Here is the verbatim content of that line: shortcut: type___LedgerSpecifier.ShortcutValue = ... It seems that the problem in at least this case is that this declaration of class LedgerSpecifier:
ShortcutValue = typing___NewType('ShortcutValue', builtin___int)
shortcut: type___LedgerSpecifier.ShortcutValue = ...
type___LedgerSpecifier = LedgerSpecifier Perhaps the not-yet-defined name should be quoted instead? class LedgerSpecifier:
ShortcutValue = typing___NewType('ShortcutValue', builtin___int)
shortcut: 'type___LedgerSpecifier.ShortcutValue' = ...
type___LedgerSpecifier = LedgerSpecifier |
The fix where I remove all class LedgerSpecifier:
ShortcutValue = typing___NewType('ShortcutValue', builtin___int)
shortcut: LedgerSpecifier.ShortcutValue = ...
type___LedgerSpecifier = LedgerSpecifier I guess the name mangler changed the prefix from |
Excellent debugging! Thanks! I changed We do have a test case which creates a similar scenario here. proto: generated pyi: This seems to pass our tests, which does mypy over the generated These links are both to version 1.22 (not yet released). Going back in time to version 1.21, the file looks like this Potential hypotheses (guessing based on what might be different): Mypy version? Different mypy flags? Different test case? Perhaps paste your entire .pyi file as generated here? Oooh interesting!! I think mypy version is to blame here. mypy started accepting these (hit the burger in the top right -> press run to run mypy) |
Updating mypy fixed it! Thanks for introducing me to mypy-play.net too. |
With mypy-protobuf 1.19, mypy passed my code. Upgrading to mypy-protobuf 1.20 changes the output to add some
global___
prefixes to types, breaking the type check. If I pin my dependency to 1.19, or just strip out these prefixes, mypy passes my code again. Is there another alternative? Perhaps an option to disable the name mangling?The text was updated successfully, but these errors were encountered: