diff --git a/docs/escaping.rst b/docs/escaping.rst index b1fd4f5..8e9dd48 100644 --- a/docs/escaping.rst +++ b/docs/escaping.rst @@ -24,8 +24,8 @@ passed to the ``FluentBundle`` constructor or to ``compile_messages``. An ``escaper`` is an object that defines the following set of attributes. The object could be a module, or a simple namespace object you could create using -``types.SimpleNamespace`` (or ``fluent_compiler.utils.SimpleNamespace`` on Python 2), or -an instance of a class with appropriate methods defined. The attributes are: +``types.SimpleNamespace``, or an instance of a class with appropriate +methods defined. The attributes are: - ``name`` - a simple text value that is used in error messages. diff --git a/src/fluent_compiler/escapers.py b/src/fluent_compiler/escapers.py index 855ef27..bb5adeb 100644 --- a/src/fluent_compiler/escapers.py +++ b/src/fluent_compiler/escapers.py @@ -1,5 +1,6 @@ +from types import SimpleNamespace + from . import codegen -from .utils import SimpleNamespace def identity(value): diff --git a/src/fluent_compiler/utils.py b/src/fluent_compiler/utils.py index 21b0928..839df57 100644 --- a/src/fluent_compiler/utils.py +++ b/src/fluent_compiler/utils.py @@ -18,27 +18,6 @@ class Any: Any = Any() -# On Python 3 we could get away with just using a class, but on Python 2 -# functions defined in the class body get wrapped with UnboundMethod, which -# causes problems. - -try: - from types import SimpleNamespace -except ImportError: - # Python 2 fallback - class SimpleNamespace: - def __init__(self, **kwargs): - self.__dict__.update(kwargs) - - def __repr__(self): - keys = sorted(self.__dict__) - items = (f"{k}={self.__dict__[k]!r}" for k in keys) - return f"{type(self).__name__}({', '.join(items)})" - - def __eq__(self, other): - return self.__dict__ == other.__dict__ - - # From spec: # NamedArgument ::= Identifier blank? ":" blank? (StringLiteral | NumberLiteral) # Identifier ::= [a-zA-Z] [a-zA-Z0-9_-]* diff --git a/tests/test_compiler.py b/tests/test_compiler.py index fdd0e86..5a3f350 100644 --- a/tests/test_compiler.py +++ b/tests/test_compiler.py @@ -1,4 +1,5 @@ import unittest +from types import SimpleNamespace from markupsafe import Markup, escape @@ -6,7 +7,6 @@ from fluent_compiler.compiler import compile_messages from fluent_compiler.errors import FluentCyclicReferenceError, FluentFormatError, FluentReferenceError from fluent_compiler.resource import FtlResource -from fluent_compiler.utils import SimpleNamespace from .test_codegen import decompile_ast_list, normalize_python from .utils import dedent_ftl