Skip to content

Commit

Permalink
Fix types for python <3.9 using typing-extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
eemeli committed Feb 11, 2023
1 parent c41c30f commit b2f8bb4
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 15 deletions.
11 changes: 8 additions & 3 deletions .github/workflows/fluent.runtime.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
run: |
python -m pip install wheel
python -m pip install --upgrade pip
python -m pip install fluent.syntax==${{ matrix.fluent-syntax }}
python -m pip install fluent.syntax==${{ matrix.fluent-syntax }} six
python -m pip install .
- name: Test
working-directory: ./fluent.runtime
Expand All @@ -53,11 +53,16 @@ jobs:
with:
python-version: 3.9
- name: Install dependencies
working-directory: ./fluent.runtime
run: |
python -m pip install wheel
python -m pip install --upgrade pip
python -m pip install flake8==6
python -m pip install mypy==1
python -m pip install .
python -m pip install flake8==6 mypy==1
- name: Install latest fluent.syntax
working-directory: ./fluent.syntax
run: |
python -m pip install .
- name: flake8
working-directory: ./fluent.runtime
run: |
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/fluent.syntax.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ jobs:
run: |
python -m pip install wheel
python -m pip install --upgrade pip
python -m pip install .
- name: Test
working-directory: ./fluent.syntax
run: |
Expand All @@ -47,10 +48,11 @@ jobs:
with:
python-version: 3.9
- name: Install dependencies
working-directory: ./fluent.syntax
run: |
python -m pip install --upgrade pip
python -m pip install flake8==6
python -m pip install mypy==1
python -m pip install .
python -m pip install flake8==6 mypy==1
- name: flake8
working-directory: ./fluent.syntax
run: |
Expand Down
7 changes: 5 additions & 2 deletions fluent.docs/setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from setuptools import setup, find_namespace_packages
from setuptools import setup

setup(
name='fluent.docs',
packages=find_namespace_packages(include=['fluent.*']),
packages=['fluent.docs'],
install_requires=[
'typing-extensions>=3.7,<5'
],
)
3 changes: 2 additions & 1 deletion fluent.runtime/fluent/runtime/bundle.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import babel
import babel.numbers
import babel.plural
from typing import Any, Callable, Dict, List, Literal, TYPE_CHECKING, Tuple, Union, cast
from typing import Any, Callable, Dict, List, TYPE_CHECKING, Tuple, Union, cast
from typing_extensions import Literal

from fluent.syntax import ast as FTL

Expand Down
4 changes: 1 addition & 3 deletions fluent.runtime/fluent/runtime/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ def modified(self, **replacements: Any) -> Generator['ResolverEnvironment', None
yield self
self.current = old_current

def modified_for_term_reference(
self, args: Union[Dict[str, Any], None] = None
) -> contextlib._GeneratorContextManager['ResolverEnvironment']:
def modified_for_term_reference(self, args: Union[Dict[str, Any], None] = None) -> Any:
return self.modified(args=args if args is not None else {},
error_for_missing_arg=False)

Expand Down
3 changes: 2 additions & 1 deletion fluent.runtime/fluent/runtime/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
from babel import Locale
from babel.dates import format_date, format_time, get_datetime_format, get_timezone
from babel.numbers import NumberPattern, parse_pattern
from typing import Any, Dict, Literal, Type, TypeVar, Union, cast
from typing import Any, Dict, Type, TypeVar, Union, cast
from typing_extensions import Literal

FORMAT_STYLE_DECIMAL = "decimal"
FORMAT_STYLE_CURRENCY = "currency"
Expand Down
1 change: 1 addition & 0 deletions fluent.runtime/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
'attrs',
'babel',
'pytz',
'typing-extensions>=3.7,<5'
],
test_suite='tests',
)
1 change: 1 addition & 0 deletions fluent.runtime/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ deps =
attrs==19.1.0
babel==2.7.0
pytz==2019.2
typing-extensions==3.7
syntax: .
commands = ./runtests.py

Expand Down
4 changes: 2 additions & 2 deletions fluent.syntax/fluent/syntax/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,10 @@ def parse(self) -> Dict[str, Any]:

class StringLiteral(Literal):
def parse(self) -> Dict[str, str]:
def from_escape_sequence(matchobj: re.Match[str]) -> str:
def from_escape_sequence(matchobj: Any) -> str:
c, codepoint4, codepoint6 = matchobj.groups()
if c:
return c
return cast(str, c)
codepoint = int(codepoint4 or codepoint6, 16)
if codepoint <= 0xD7FF or 0xE000 <= codepoint:
return chr(codepoint)
Expand Down
3 changes: 2 additions & 1 deletion fluent.syntax/fluent/syntax/stream.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Callable, Literal, Union
from typing import Callable, Union
from typing_extensions import Literal
from .errors import ParseError


Expand Down
3 changes: 3 additions & 0 deletions fluent.syntax/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,8 @@
],
packages=['fluent.syntax'],
package_data={'fluent.syntax': ['py.typed']},
install_requires=[
'typing-extensions>=3.7,<5'
],
test_suite='tests.syntax'
)
2 changes: 2 additions & 0 deletions fluent.syntax/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ skipsdist=True
[testenv]
setenv =
PYTHONPATH = {toxinidir}
deps =
typing-extensions==3.7
commands = ./runtests.py

0 comments on commit b2f8bb4

Please sign in to comment.