Skip to content

Commit c498d15

Browse files
committed
Fix types for python <3.9 using typing-extensions
1 parent c41c30f commit c498d15

File tree

12 files changed

+33
-15
lines changed

12 files changed

+33
-15
lines changed

.github/workflows/fluent.runtime.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
run: |
4040
python -m pip install wheel
4141
python -m pip install --upgrade pip
42-
python -m pip install fluent.syntax==${{ matrix.fluent-syntax }}
42+
python -m pip install fluent.syntax==${{ matrix.fluent-syntax }} six
4343
python -m pip install .
4444
- name: Test
4545
working-directory: ./fluent.runtime
@@ -53,11 +53,16 @@ jobs:
5353
with:
5454
python-version: 3.9
5555
- name: Install dependencies
56+
working-directory: ./fluent.runtime
5657
run: |
5758
python -m pip install wheel
5859
python -m pip install --upgrade pip
59-
python -m pip install flake8==6
60-
python -m pip install mypy==1
60+
python -m pip install .
61+
python -m pip install flake8==6 mypy==1 types-babel types-pytz
62+
- name: Install latest fluent.syntax
63+
working-directory: ./fluent.syntax
64+
run: |
65+
python -m pip install .
6166
- name: flake8
6267
working-directory: ./fluent.runtime
6368
run: |

.github/workflows/fluent.syntax.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ jobs:
3535
run: |
3636
python -m pip install wheel
3737
python -m pip install --upgrade pip
38+
python -m pip install .
3839
- name: Test
3940
working-directory: ./fluent.syntax
4041
run: |
@@ -47,10 +48,11 @@ jobs:
4748
with:
4849
python-version: 3.9
4950
- name: Install dependencies
51+
working-directory: ./fluent.syntax
5052
run: |
5153
python -m pip install --upgrade pip
52-
python -m pip install flake8==6
53-
python -m pip install mypy==1
54+
python -m pip install .
55+
python -m pip install flake8==6 mypy==1
5456
- name: flake8
5557
working-directory: ./fluent.syntax
5658
run: |

fluent.docs/setup.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
from setuptools import setup, find_namespace_packages
1+
from setuptools import setup
22

33
setup(
44
name='fluent.docs',
5-
packages=find_namespace_packages(include=['fluent.*']),
5+
packages=['fluent.docs'],
6+
install_requires=[
7+
'typing-extensions>=3.7,<5'
8+
],
69
)

fluent.runtime/fluent/runtime/bundle.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import babel
22
import babel.numbers
33
import babel.plural
4-
from typing import Any, Callable, Dict, List, Literal, TYPE_CHECKING, Tuple, Union, cast
4+
from typing import Any, Callable, Dict, List, TYPE_CHECKING, Tuple, Union, cast
5+
from typing_extensions import Literal
56

67
from fluent.syntax import ast as FTL
78

fluent.runtime/fluent/runtime/resolver.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,7 @@ def modified(self, **replacements: Any) -> Generator['ResolverEnvironment', None
6868
yield self
6969
self.current = old_current
7070

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

fluent.runtime/fluent/runtime/types.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
from babel import Locale
88
from babel.dates import format_date, format_time, get_datetime_format, get_timezone
99
from babel.numbers import NumberPattern, parse_pattern
10-
from typing import Any, Dict, Literal, Type, TypeVar, Union, cast
10+
from typing import Any, Dict, Type, TypeVar, Union, cast
11+
from typing_extensions import Literal
1112

1213
FORMAT_STYLE_DECIMAL = "decimal"
1314
FORMAT_STYLE_CURRENCY = "currency"

fluent.runtime/setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
'attrs',
3434
'babel',
3535
'pytz',
36+
'typing-extensions>=3.7,<5'
3637
],
3738
test_suite='tests',
3839
)

fluent.runtime/tox.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ deps =
1212
attrs==19.1.0
1313
babel==2.7.0
1414
pytz==2019.2
15+
typing-extensions==3.7
1516
syntax: .
1617
commands = ./runtests.py
1718

fluent.syntax/fluent/syntax/ast.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,10 @@ def parse(self) -> Dict[str, Any]:
208208

209209
class StringLiteral(Literal):
210210
def parse(self) -> Dict[str, str]:
211-
def from_escape_sequence(matchobj: re.Match[str]) -> str:
211+
def from_escape_sequence(matchobj: Any) -> str:
212212
c, codepoint4, codepoint6 = matchobj.groups()
213213
if c:
214-
return c
214+
return cast(str, c)
215215
codepoint = int(codepoint4 or codepoint6, 16)
216216
if codepoint <= 0xD7FF or 0xE000 <= codepoint:
217217
return chr(codepoint)

fluent.syntax/fluent/syntax/stream.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from typing import Callable, Literal, Union
1+
from typing import Callable, Union
2+
from typing_extensions import Literal
23
from .errors import ParseError
34

45

fluent.syntax/setup.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,8 @@
2626
],
2727
packages=['fluent.syntax'],
2828
package_data={'fluent.syntax': ['py.typed']},
29+
install_requires=[
30+
'typing-extensions>=3.7,<5'
31+
],
2932
test_suite='tests.syntax'
3033
)

fluent.syntax/tox.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@ skipsdist=True
77
[testenv]
88
setenv =
99
PYTHONPATH = {toxinidir}
10+
deps =
11+
typing-extensions==3.7
1012
commands = ./runtests.py

0 commit comments

Comments
 (0)