Skip to content

Commit 7e1c4be

Browse files
authored
Drop Python 2.7, 3.5 support, add 3.6-3.9 for fluent.syntax (#161)
* Declare compat with current python version, drop 2.7, 3.5. Also adjust testing matrix to that. * Drop six * Use pyugrade --py36-plus to modernize syntax. * Update version number and CHANGELOG
1 parent c9910d8 commit 7e1c4be

20 files changed

+80
-106
lines changed

.github/workflows/fluent.syntax.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
runs-on: ubuntu-latest
2525
strategy:
2626
matrix:
27-
python-version: [2.7, 3.5, 3.6, 3.7, 3.8, pypy2, pypy3]
27+
python-version: [3.6, 3.7, 3.8, 3.9, pypy3]
2828
steps:
2929
- uses: actions/checkout@v2
3030
- uses: actions/setup-python@v2
@@ -35,7 +35,6 @@ jobs:
3535
run: |
3636
python -m pip install wheel
3737
python -m pip install --upgrade pip
38-
python -m pip install six
3938
- name: Test
4039
working-directory: ./fluent.syntax
4140
run: |
@@ -47,7 +46,7 @@ jobs:
4746
- uses: actions/checkout@v2
4847
- uses: actions/setup-python@v2
4948
with:
50-
python-version: 3.7
49+
python-version: 3.9
5150
- name: Install dependencies
5251
run: |
5352
python -m pip install --upgrade pip

fluent.syntax/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## fluent.syntax 0.19 (TBD)
4+
5+
- Drop support for Python 2.7 and 3.5
6+
- Add support for Python 3.6 through 3.9
7+
38
## fluent.syntax 0.18.1 (September 15, 2020)
49

510
- Fix serialization of multiline patterns starting with special characters. (#156)

fluent.syntax/fluent/syntax/ast.py

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
# coding=utf-8
2-
from __future__ import unicode_literals
31
import re
42
import sys
53
import json
6-
import six
74

85

96
def to_json(value, fn=None):
@@ -44,7 +41,7 @@ def scalars_equal(node1, node2, ignored_fields):
4441
return node1 == node2
4542

4643

47-
class BaseNode(object):
44+
class BaseNode:
4845
"""Base class for all Fluent AST nodes.
4946
5047
All productions described in the ASDL subclass BaseNode, including Span and
@@ -125,7 +122,7 @@ class SyntaxNode(BaseNode):
125122
"""Base class for AST nodes which can have Spans."""
126123

127124
def __init__(self, span=None, **kwargs):
128-
super(SyntaxNode, self).__init__(**kwargs)
125+
super().__init__(**kwargs)
129126
self.span = span
130127

131128
def add_span(self, start, end):
@@ -134,7 +131,7 @@ def add_span(self, start, end):
134131

135132
class Resource(SyntaxNode):
136133
def __init__(self, body=None, **kwargs):
137-
super(Resource, self).__init__(**kwargs)
134+
super().__init__(**kwargs)
138135
self.body = body or []
139136

140137

@@ -145,7 +142,7 @@ class Entry(SyntaxNode):
145142
class Message(Entry):
146143
def __init__(self, id, value=None, attributes=None,
147144
comment=None, **kwargs):
148-
super(Message, self).__init__(**kwargs)
145+
super().__init__(**kwargs)
149146
self.id = id
150147
self.value = value
151148
self.attributes = attributes or []
@@ -155,7 +152,7 @@ def __init__(self, id, value=None, attributes=None,
155152
class Term(Entry):
156153
def __init__(self, id, value, attributes=None,
157154
comment=None, **kwargs):
158-
super(Term, self).__init__(**kwargs)
155+
super().__init__(**kwargs)
159156
self.id = id
160157
self.value = value
161158
self.attributes = attributes or []
@@ -164,7 +161,7 @@ def __init__(self, id, value, attributes=None,
164161

165162
class Pattern(SyntaxNode):
166163
def __init__(self, elements, **kwargs):
167-
super(Pattern, self).__init__(**kwargs)
164+
super().__init__(**kwargs)
168165
self.elements = elements
169166

170167

@@ -174,13 +171,13 @@ class PatternElement(SyntaxNode):
174171

175172
class TextElement(PatternElement):
176173
def __init__(self, value, **kwargs):
177-
super(TextElement, self).__init__(**kwargs)
174+
super().__init__(**kwargs)
178175
self.value = value
179176

180177

181178
class Placeable(PatternElement):
182179
def __init__(self, expression, **kwargs):
183-
super(Placeable, self).__init__(**kwargs)
180+
super().__init__(**kwargs)
184181
self.expression = expression
185182

186183

@@ -191,7 +188,7 @@ class Expression(SyntaxNode):
191188
class Literal(Expression):
192189
"""An abstract base class for literals."""
193190
def __init__(self, value, **kwargs):
194-
super(Literal, self).__init__(**kwargs)
191+
super().__init__(**kwargs)
195192
self.value = value
196193

197194
def parse(self):
@@ -206,7 +203,7 @@ def from_escape_sequence(matchobj):
206203
return c
207204
codepoint = int(codepoint4 or codepoint6, 16)
208205
if codepoint <= 0xD7FF or 0xE000 <= codepoint:
209-
return six.unichr(codepoint)
206+
return chr(codepoint)
210207
# Escape sequences reresenting surrogate code points are
211208
# well-formed but invalid in Fluent. Replace them with U+FFFD
212209
# REPLACEMENT CHARACTER.
@@ -235,98 +232,98 @@ def parse(self):
235232

236233
class MessageReference(Expression):
237234
def __init__(self, id, attribute=None, **kwargs):
238-
super(MessageReference, self).__init__(**kwargs)
235+
super().__init__(**kwargs)
239236
self.id = id
240237
self.attribute = attribute
241238

242239

243240
class TermReference(Expression):
244241
def __init__(self, id, attribute=None, arguments=None, **kwargs):
245-
super(TermReference, self).__init__(**kwargs)
242+
super().__init__(**kwargs)
246243
self.id = id
247244
self.attribute = attribute
248245
self.arguments = arguments
249246

250247

251248
class VariableReference(Expression):
252249
def __init__(self, id, **kwargs):
253-
super(VariableReference, self).__init__(**kwargs)
250+
super().__init__(**kwargs)
254251
self.id = id
255252

256253

257254
class FunctionReference(Expression):
258255
def __init__(self, id, arguments, **kwargs):
259-
super(FunctionReference, self).__init__(**kwargs)
256+
super().__init__(**kwargs)
260257
self.id = id
261258
self.arguments = arguments
262259

263260

264261
class SelectExpression(Expression):
265262
def __init__(self, selector, variants, **kwargs):
266-
super(SelectExpression, self).__init__(**kwargs)
263+
super().__init__(**kwargs)
267264
self.selector = selector
268265
self.variants = variants
269266

270267

271268
class CallArguments(SyntaxNode):
272269
def __init__(self, positional=None, named=None, **kwargs):
273-
super(CallArguments, self).__init__(**kwargs)
270+
super().__init__(**kwargs)
274271
self.positional = [] if positional is None else positional
275272
self.named = [] if named is None else named
276273

277274

278275
class Attribute(SyntaxNode):
279276
def __init__(self, id, value, **kwargs):
280-
super(Attribute, self).__init__(**kwargs)
277+
super().__init__(**kwargs)
281278
self.id = id
282279
self.value = value
283280

284281

285282
class Variant(SyntaxNode):
286283
def __init__(self, key, value, default=False, **kwargs):
287-
super(Variant, self).__init__(**kwargs)
284+
super().__init__(**kwargs)
288285
self.key = key
289286
self.value = value
290287
self.default = default
291288

292289

293290
class NamedArgument(SyntaxNode):
294291
def __init__(self, name, value, **kwargs):
295-
super(NamedArgument, self).__init__(**kwargs)
292+
super().__init__(**kwargs)
296293
self.name = name
297294
self.value = value
298295

299296

300297
class Identifier(SyntaxNode):
301298
def __init__(self, name, **kwargs):
302-
super(Identifier, self).__init__(**kwargs)
299+
super().__init__(**kwargs)
303300
self.name = name
304301

305302

306303
class BaseComment(Entry):
307304
def __init__(self, content=None, **kwargs):
308-
super(BaseComment, self).__init__(**kwargs)
305+
super().__init__(**kwargs)
309306
self.content = content
310307

311308

312309
class Comment(BaseComment):
313310
def __init__(self, content=None, **kwargs):
314-
super(Comment, self).__init__(content, **kwargs)
311+
super().__init__(content, **kwargs)
315312

316313

317314
class GroupComment(BaseComment):
318315
def __init__(self, content=None, **kwargs):
319-
super(GroupComment, self).__init__(content, **kwargs)
316+
super().__init__(content, **kwargs)
320317

321318

322319
class ResourceComment(BaseComment):
323320
def __init__(self, content=None, **kwargs):
324-
super(ResourceComment, self).__init__(content, **kwargs)
321+
super().__init__(content, **kwargs)
325322

326323

327324
class Junk(SyntaxNode):
328325
def __init__(self, content=None, annotations=None, **kwargs):
329-
super(Junk, self).__init__(**kwargs)
326+
super().__init__(**kwargs)
330327
self.content = content
331328
self.annotations = annotations or []
332329

@@ -336,14 +333,14 @@ def add_annotation(self, annot):
336333

337334
class Span(BaseNode):
338335
def __init__(self, start, end, **kwargs):
339-
super(Span, self).__init__(**kwargs)
336+
super().__init__(**kwargs)
340337
self.start = start
341338
self.end = end
342339

343340

344341
class Annotation(SyntaxNode):
345342
def __init__(self, code, arguments=None, message=None, **kwargs):
346-
super(Annotation, self).__init__(**kwargs)
343+
super().__init__(**kwargs)
347344
self.code = code
348345
self.arguments = arguments or []
349346
self.message = message

fluent.syntax/fluent/syntax/errors.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
from __future__ import unicode_literals
2-
3-
41
class ParseError(Exception):
52
def __init__(self, code, *args):
63
self.code = code

fluent.syntax/fluent/syntax/parser.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from __future__ import unicode_literals
21
import re
32
from . import ast
43
from .stream import EOF, EOL, FluentParserStream
@@ -25,7 +24,7 @@ def decorated(self, ps, *args, **kwargs):
2524
return decorated
2625

2726

28-
class FluentParser(object):
27+
class FluentParser:
2928
"""This class is used to parse Fluent source content.
3029
3130
``with_spans`` enables source information in the form of
@@ -469,7 +468,7 @@ def get_escape_sequence(self, ps):
469468

470469
if next == '\\' or next == '"':
471470
ps.next()
472-
return '\\{}'.format(next)
471+
return f'\\{next}'
473472

474473
if next == 'u':
475474
return self.get_unicode_escape_sequence(ps, next, 4)
@@ -485,10 +484,10 @@ def get_unicode_escape_sequence(self, ps, u, digits):
485484
for _ in range(digits):
486485
ch = ps.take_hex_digit()
487486
if not ch:
488-
raise ParseError('E0026', '\\{}{}{}'.format(u, sequence, ps.current_char))
487+
raise ParseError('E0026', f'\\{u}{sequence}{ps.current_char}')
489488
sequence += ch
490489

491-
return '\\{}{}'.format(u, sequence)
490+
return f'\\{u}{sequence}'
492491

493492
@with_span
494493
def get_placeable(self, ps):

0 commit comments

Comments
 (0)