Skip to content

Commit 1f9a565

Browse files
committed
refactor: exclude SimpleNamespace from utils
1 parent 600be9e commit 1f9a565

File tree

4 files changed

+5
-25
lines changed

4 files changed

+5
-25
lines changed

docs/escaping.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ passed to the ``FluentBundle`` constructor or to ``compile_messages``.
2424
2525
An ``escaper`` is an object that defines the following set of attributes. The
2626
object could be a module, or a simple namespace object you could create using
27-
``types.SimpleNamespace`` (or ``fluent_compiler.utils.SimpleNamespace`` on Python 2), or
28-
an instance of a class with appropriate methods defined. The attributes are:
27+
``types.SimpleNamespace``, or an instance of a class with appropriate
28+
methods defined. The attributes are:
2929

3030
- ``name`` - a simple text value that is used in error messages.
3131

src/fluent_compiler/escapers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
from types import SimpleNamespace
2+
13
from . import codegen
2-
from .utils import SimpleNamespace
34

45

56
def identity(value):

src/fluent_compiler/utils.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,6 @@ class Any:
1818
Any = Any()
1919

2020

21-
# On Python 3 we could get away with just using a class, but on Python 2
22-
# functions defined in the class body get wrapped with UnboundMethod, which
23-
# causes problems.
24-
25-
try:
26-
from types import SimpleNamespace
27-
except ImportError:
28-
# Python 2 fallback
29-
class SimpleNamespace:
30-
def __init__(self, **kwargs):
31-
self.__dict__.update(kwargs)
32-
33-
def __repr__(self):
34-
keys = sorted(self.__dict__)
35-
items = (f"{k}={self.__dict__[k]!r}" for k in keys)
36-
return f"{type(self).__name__}({', '.join(items)})"
37-
38-
def __eq__(self, other):
39-
return self.__dict__ == other.__dict__
40-
41-
4221
# From spec:
4322
# NamedArgument ::= Identifier blank? ":" blank? (StringLiteral | NumberLiteral)
4423
# Identifier ::= [a-zA-Z] [a-zA-Z0-9_-]*

tests/test_compiler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import unittest
2+
from types import SimpleNamespace
23

34
from markupsafe import Markup, escape
45

56
from fluent_compiler import codegen
67
from fluent_compiler.compiler import compile_messages
78
from fluent_compiler.errors import FluentCyclicReferenceError, FluentFormatError, FluentReferenceError
89
from fluent_compiler.resource import FtlResource
9-
from fluent_compiler.utils import SimpleNamespace
1010

1111
from .test_codegen import decompile_ast_list, normalize_python
1212
from .utils import dedent_ftl

0 commit comments

Comments
 (0)