Skip to content

Commit

Permalink
🧹 Remove warnings during tests (#6122)
Browse files Browse the repository at this point in the history
We were persistently printing 2 deprecation warnings during unit tests. These warning originated from old versions of the Lark parser and the Pydantic library, that were using deprecated Python APIs.

Upgrade both libraries to newer versions; the warnings are now gone.

Because we cache Lark parsers on disk, we need to make sure to mix the Lark version into the cache key so that we don't load old parsers into a new version of the library.

We can't seem to go higher than `1.1.9`, because when we do we run into the following parsing problem:

```
E           exceptions.InvalidArgumentTypeException: Invalid Argument Type {'command': 'forward', 'invalid_type': Markup('text'), 'allowed_types': 'a number or input from `ask`', 'invalid_argument': '100', 'line_number': 1}

We detected that `forward` doesn't work with `100` because it is text. Can you try changing `100` to a number or input from `ask`? at line [1]
```

**How to test**

If all tests pass, this is good to go.
  • Loading branch information
rix0rrr authored Jan 22, 2025
1 parent f8003e0 commit 5709035
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
3 changes: 3 additions & 0 deletions exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ def error_location(self):
return [self.arguments['line_number']]
return None

def __str__(self):
return f'{self.error_code} {repr(self.arguments)}'


class WarningException(HedyException):
"""Fixed That For You warning/exception.
Expand Down
2 changes: 2 additions & 0 deletions hedy.py
Original file line number Diff line number Diff line change
Expand Up @@ -3612,6 +3612,8 @@ def get_parser(level, lang="en", keep_all_tokens=False, skip_faulty=False):
grammar,
str(sys.version_info[:2]),
str(parser_opts),
# When we upgrade Lark, make sure to not load cached parsers from old versions
str(lark.__version__),
)).encode()).hexdigest()

cached_parser_file = f"cached-parser-{level}-{lang}-{unique_parser_hash}.pkl"
Expand Down
6 changes: 4 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Flask==3.0.2
Werkzeug==3.0.6
lark==1.1.1
# We cannot go higher than this, because starting 1.2.1+
# we parse "100" as text instead of a number.
lark==1.1.9
gunicorn==22.0.0
flask-compress==1.4.0
requests==2.32.0
Expand All @@ -10,7 +12,7 @@ boto3>=1.16.50
MarkupSafe==2.1.2
ruamel.yaml==0.18.6
docopt==0.6.2
pydantic==1.10.13
pydantic==1.10.21
lazy==1.4
PySumTypes==0.0.1
beautifulsoup4==4.9.3
Expand Down

0 comments on commit 5709035

Please sign in to comment.