Skip to content

Fix TextIO import error#205

Open
qthibeault wants to merge 1 commit into
nickovic:masterfrom
qthibeault:fix-typing-import-errors
Open

Fix TextIO import error#205
qthibeault wants to merge 1 commit into
nickovic:masterfrom
qthibeault:fix-typing-import-errors

Conversation

@qthibeault

Copy link
Copy Markdown
Contributor

When using Python versions >= 3.12, importing RTAMT produces the following error:

Traceback (most recent call last):
  File "/home/runner/work/psy-taliro/psy-taliro/examples/f16.py", line 13, in <module>
    from staliro.specifications import rtamt
  File "/home/runner/work/psy-taliro/psy-taliro/src/staliro/specifications/rtamt.py", line 6, in <module>
    from rtamt import StlDenseTimeSpecification, StlDiscreteTimeSpecification
  File "/home/runner/.local/share/hatch/env/virtual/psy-taliro/dEx5JRFg/psy-taliro/lib/python3.13/site-packages/rtamt/__init__.py", line 5, in <module>
    from rtamt.spec.stl.discrete_time.specification import StlDiscreteTimeSpecification
  File "/home/runner/.local/share/hatch/env/virtual/psy-taliro/dEx5JRFg/psy-taliro/lib/python3.13/site-packages/rtamt/spec/stl/discrete_time/specification.py", line 3, in <module>
    from rtamt.syntax.ast.parser.stl.specification_parser import StlAst
  File "/home/runner/.local/share/hatch/env/virtual/psy-taliro/dEx5JRFg/psy-taliro/lib/python3.13/site-packages/rtamt/syntax/ast/parser/stl/specification_parser.py", line 2, in <module>
    from rtamt.syntax.ast.parser.stl.parser_visitor import StlAstParserVisitor
  File "/home/runner/.local/share/hatch/env/virtual/psy-taliro/dEx5JRFg/psy-taliro/lib/python3.13/site-packages/rtamt/syntax/ast/parser/stl/parser_visitor.py", line 4, in <module>
    from rtamt.antlr.parser.stl.StlParserVisitor import StlParserVisitor
  File "/home/runner/.local/share/hatch/env/virtual/psy-taliro/dEx5JRFg/psy-taliro/lib/python3.13/site-packages/rtamt/antlr/parser/stl/StlParserVisitor.py", line 2, in <module>
    from antlr4 import *
  File "/home/runner/.local/share/hatch/env/virtual/psy-taliro/dEx5JRFg/psy-taliro/lib/python3.13/site-packages/antlr4/__init__.py", line 5, in <module>
    from antlr4.CommonTokenStream import CommonTokenStream
  File "/home/runner/.local/share/hatch/env/virtual/psy-taliro/dEx5JRFg/psy-taliro/lib/python3.13/site-packages/antlr4/CommonTokenStream.py", line 33, in <module>
    from antlr4.Lexer import Lexer
  File "/home/runner/.local/share/hatch/env/virtual/psy-taliro/dEx5JRFg/psy-taliro/lib/python3.13/site-packages/antlr4/Lexer.py", line 12, in <module>
    from typing.io import TextIO
ModuleNotFoundError: No module named 'typing.io'; 'typing' is not a package

The typing.io module was deprecated in Python 3.8 and was scheduled for removal in 3.12, and the types were moved into the base typing module as of Python 3.6. The current usage of typing.io in some RTAMT modules means that newer versions of Python are not supported.

This fix adds a guard that selects the correct import for the TextIO type depending on the version reported by sys.version_info. This approach was chosen rather than just fixing the import to maximize backward compatibility, since the library currently indicates that it supports Python versions earlier than 3.6.

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.

1 participant