-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Py runtime: Move to relative imports #4705
base: dev
Are you sure you want to change the base?
Conversation
3bd8e91
to
8d82b49
Compare
@@ -52,7 +52,7 @@ def removeErrorListeners(self): | |||
def getTokenTypeMap(self): | |||
tokenNames = self.getTokenNames() | |||
if tokenNames is None: | |||
from antlr4.error.Errors import UnsupportedOperationException | |||
from .error.Errors import UnsupportedOperationException |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm guessing that the reason these imports were made lazy was because of circular import issues... This MR should start to straighten that out.
from antlr4.error.ErrorStrategy import BailErrorStrategy | ||
from antlr4.error.DiagnosticErrorListener import DiagnosticErrorListener | ||
from antlr4.Utils import str_list | ||
from .Token import Token |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the future I would recommend making these explicit export based imports, as mentioned in https://mypy.readthedocs.io/en/stable/command_line.html#cmdoption-mypy-no-implicit-reexport.
I didn't do that here because I would try to add some validation of this expectation.
@pelson thanks for this. LGTM apart from my 2 comments. |
Thanks @ericvergnaud - I think you forgot to hit submit review. Comments missing. |
import importlib | ||
from antlr4 import * | ||
|
||
from . import * |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the only place where import *
is not fixed - I would be happy to follow-up in another PR to make the names being used explicit.
from antlr4.error.Errors import LexerNoViableAltException | ||
from antlr4.tree.Tree import ParseTree | ||
from antlr4.tree.Trees import Trees | ||
from ..Lexer import Lexer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file is generated, and generated files cannot use relative imports since they normally sit outside the antlr code base. Please revert.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is XPath.py
really auto-generated? I don't see it in https://github.com/antlr/antlr4/blob/dev/doc/releasing-antlr.md#build-xpath-parsers (unlike XPathLexer.py
which definitely is auto-generated)
@@ -1,5 +1,11 @@ | |||
# Generated from XPathLexer.g4 by ANTLR 4.13.1 | |||
from antlr4 import * | |||
from ..Lexer import Lexer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file is generated, and generated files cannot use relative imports since they normally sit outside the antlr code base. Please revert
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reverted in my update
Signed-off-by: Phil Elson <[email protected]>
8d82b49
to
06417ca
Compare
This also fixes a few
from antlr4 import *
, which is considered bad practice unless being done to expose an interface (https://peps.python.org/pep-0008/#imports)My changes seem to modify generated files in
antlr4.xpath
. I didn't yet look at fixing the generator.There remains some significant issues withe the namespaces being exposed in the runtime - I would be happy to follow up after this change to tighten the names being made publicly available.