Skip to content

Conversation

@Beakerboy
Copy link
Contributor

No description provided.

@github-actions

This comment has been minimized.

@AlexWaygood
Copy link
Member

The stubs need to have the directory structure stubs/antlr4-python3-runtime/antrl4. The outer directory is the name of the PyPI runtime distribution; the inner directory is the name of the package that can be imported at runtime after installing the runtime distribution

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@Beakerboy
Copy link
Contributor Author

Beakerboy commented Dec 20, 2023

It looks like I can easily clean up the Test / Test typeshed with pyright failures by referencing and tracing through the source. for the Third-party stubtests, what's the best way to resolve issues where the source devs initialize variables to None?

@AlexWaygood
Copy link
Member

AlexWaygood commented Dec 20, 2023

for the Third-party stubtests, what's the best way to resolve issues where the source devs initialize variables to None?

I haven't looked at the antlr4 source code at all, but if the runtime has a function like this:

def foo(name=None): ...

And you've written a stub like this:

def foo(name: str = ...) -> None: ...

Then, to make stubtest happy, you generally need to change it to something like this:

def foo(name: str | None = None) -> None ...

Since the function obviously won't raise an error if None is passed (since None is the default)

@srittau
Copy link
Collaborator

srittau commented Dec 20, 2023

Most of the pyright errors seem to be referencing missing generic arguments. The best option is to add the proper generic arguments. But if you don't have the bandwidth for that, it's fine to use Incomplete (from the _typeshed module) for now. This is a marker that proper types need to be added at some point: set -> set[Incomplete], dict -> dict[Incomplete, Incomplete] etc.

I haven't looked at the stubtest problems yet, but this indicates a mismatch between the implementation and the stubs.

@Beakerboy
Copy link
Contributor Author

@srittau I have half the missing generic arguments fixed in a dev branch. I'm looking at the source to make sure TokenName: list is actually TokenName: list[str]. Thanks for the "Incomplete" hint. If I find one excessively difficult, I'll make sure to use that.

@github-actions

This comment has been minimized.

@Beakerboy
Copy link
Contributor Author

perl -pi -e 's/(def.*)\): \.\.\./$1\) -> Incomplete: \.\.\./g' *.pyi to the rescue

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@Beakerboy
Copy link
Contributor Author

Beakerboy commented Dec 24, 2023

Any advice on these errors?

error: antlr4.xpath.XPathLexer.StringIO.truncate is inconsistent, stub argument "__size" differs from runtime argument "pos" 
Stub: in file /home/runner/work/typeshed/typeshed/stubs/antlr4-python3-runtime/antlr4/xpath/XPathLexer.pyi:73
def (self: io.IOBase, Union[builtins.int, None] =) -> builtins.int 
Runtime: def (self, pos=None, /)

I don’t see any calls to StringIO.truncate in XPathLexer.pyi, and XPathLexer.pyi is not even 73 lines long‽

@AlexWaygood
Copy link
Member

Any advice on these errors?

error: antlr4.xpath.XPathLexer.StringIO.truncate is inconsistent, stub argument "__size" differs from runtime argument "pos" 
Stub: in file /home/runner/work/typeshed/typeshed/stubs/antlr4-python3-runtime/antlr4/xpath/XPathLexer.pyi:73
def (self: io.IOBase, Union[builtins.int, None] =) -> builtins.int 
Runtime: def (self, pos=None, /)

I don’t see any calls to StringIO.truncate in XPathLexer.pyi, and XPathLexer.pyi is not even 73 lines long‽

Looks like it's because you're re-exporting StringIO from XPathLexer.pyi, when you should just be importing it without re-exporting it. Replace from io import StringIO as StringIO at the top of the file with from io import StringIO.

@Beakerboy
Copy link
Contributor Author

Thanks! This is the way stubgen created the file. Should I remove the “as Foo” from all the imports?

@Beakerboy
Copy link
Contributor Author

Last errors:

error: antlr4.tree.Tree.ParserRuleContext is not present at runtime
Stub: in file /home/runner/work/typeshed/typeshed/stubs/antlr4-python3-runtime/antlr4/tree/Tree.pyi:23
Any
Runtime:
MISSING

@github-actions

This comment has been minimized.

@github-actions
Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@Beakerboy
Copy link
Contributor Author

All green and good to go from my end.

@Beakerboy
Copy link
Contributor Author

@AlexWaygood what’s the usual wait time from “all good” to “merge”? Anything I need to do?

@AlexWaygood
Copy link
Member

@AlexWaygood what’s the usual wait time from “all good” to “merge”? Anything I need to do?

Sorry for the wait. I'm afraid I'm more busy than usual at the moment, so probably won't be able to take a proper look at this soon. Hopefully somebody else on the team will be able to take a look soon, but I'm afraid we're all volunteers, so I can't make any promises about timescale here :(

@Beakerboy
Copy link
Contributor Author

@AlexWaygood No problem. I noticed there were other mergers and wanted to make sure there wasn’t anything I needed to do.

Copy link
Collaborator

@srittau srittau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Looks mostly good to me, although I didn't compare it to the implementation in-depth. A few things I noticed below.

Beakerboy and others added 10 commits January 15, 2024 08:59
Co-authored-by: Sebastian Rittau <srittau@rittau.biz>
Co-authored-by: Sebastian Rittau <srittau@rittau.biz>
Co-authored-by: Sebastian Rittau <srittau@rittau.biz>
Co-authored-by: Sebastian Rittau <srittau@rittau.biz>
Co-authored-by: Sebastian Rittau <srittau@rittau.biz>
Co-authored-by: Sebastian Rittau <srittau@rittau.biz>
Co-authored-by: Sebastian Rittau <srittau@rittau.biz>
Co-authored-by: Sebastian Rittau <srittau@rittau.biz>
Co-authored-by: Sebastian Rittau <srittau@rittau.biz>
@srittau
Copy link
Collaborator

srittau commented Jan 15, 2024

The "Run mypy on the test cases" error is unrelated.

@github-actions
Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@github-actions
Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@github-actions
Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@srittau srittau merged commit 64f7da9 into python:main Jan 15, 2024
@Beakerboy
Copy link
Contributor Author

Thanks so much! I’m curious how long it takes for the types_antlr4 package to show up at PYPI?

@srittau
Copy link
Collaborator

srittau commented Jan 15, 2024

The types are built once per day, I think during the night UTC time.

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