diff --git a/astor/code_gen.py b/astor/code_gen.py
index ecaf388..157d2cc 100644
--- a/astor/code_gen.py
+++ b/astor/code_gen.py
@@ -663,8 +663,14 @@ class SourceGenerator(ExplicitNodeVisitor):
             self.comma_list(node.elts)
 
     def visit_Set(self, node):
-        with self.delimit('{}'):
-            self.comma_list(node.elts)
+        if node.elts:
+            with self.delimit('{}'):
+                self.comma_list(node.elts)
+        else:
+            # If we tried to use "{}" to represent an empty set, it would be
+            # interpreted as an empty dictionary. We can't use "set()" either
+            # because the name "set" might be rebound.
+            self.write('{1}.__class__()')
 
     def visit_Dict(self, node):
         set_precedence(Precedence.Comma, *node.values)
diff --git a/docs/changelog.rst b/docs/changelog.rst
index aeeeca2..af9256e 100644
--- a/docs/changelog.rst
+++ b/docs/changelog.rst
@@ -42,6 +42,11 @@ Bug fixes
 .. _`Issue 85`: https://github.com/berkerpeksag/astor/issues/85
 .. _`Issue 100`: https://github.com/berkerpeksag/astor/issues/100
 
+* Improved code generation to support empty sets.
+  (Reported and fixed by Kodi Arfer in `Issue 108`_.)
+
+.. _`Issue 108`: https://github.com/berkerpeksag/astor/issues/108
+
 0.6.2 - 2017-11-11
 ------------------
 

code_gen represents an empty set as an empty dictionary
    python -c 'import ast, astor; print(astor.code_gen.to_source(ast.Set([])))'
    {}

Since Python has no literal syntax for the empty set, and we can't use `set()` because the name `set` might be rebound, I think the right representation is `{1}.__class__()`.
diff --git a/tests/test_code_gen.py b/tests/test_code_gen.py
index b8c1c6a..3a8be7b 100644
--- a/tests/test_code_gen.py
+++ b/tests/test_code_gen.py
@@ -23,8 +23,11 @@ import astor
 def canonical(srctxt):
     return textwrap.dedent(srctxt).strip()
 
+def astorexpr(x):
+    return eval(astor.to_source(ast.Expression(body=x)))
+
 def astornum(x):
-    return eval(astor.to_source(ast.Expression(body=ast.Num(n=x))))
+    return astorexpr(ast.Num(n=x))
 
 class Comparisons(object):
 
@@ -93,6 +96,14 @@ class CodegenTestCase(unittest.TestCase, Comparisons):
         source = "from ..aaa import foo, bar as bar2"
         self.assertSrcRoundtrips(source)
 
+    def test_empty_iterable_literals(self):
+        self.assertSrcRoundtrips('()')
+        self.assertSrcRoundtrips('[]')
+        self.assertSrcRoundtrips('{}')
+        # Python has no literal for empty sets, but code_gen should produce an
+        # expression that evaluates to one.
+        self.assertEqual(astorexpr(ast.Set([])), set())
+
     def test_dictionary_literals(self):
         source = "{'a': 1, 'b': 2}"
         self.assertSrcRoundtrips(source)

pip install -e .[dev]
parse_log_pytest
requirements.txt
pytest
apt-get update apt-get install -y gcc
3.9
requirements.txt
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
-e git+https://github.com/berkerpeksag/astor.git@991e6e9436c2512241e036464f99114438932d85#egg=astor
exceptiongroup==1.2.2
iniconfig==2.1.0
packaging==24.2
pluggy==1.5.0
pytest==8.3.5
tomli==2.2.1

name: astor
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.4.4=h6a678d5_1
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=3.0.16=h5eee18b_0
  - pip=25.0=py39h06a4308_0
  - python=3.9.21=he870216_1
  - readline=8.2=h5eee18b_0
  - setuptools=75.8.0=py39h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - tzdata=2025a=h04d1e81_0
  - wheel=0.45.1=py39h06a4308_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - exceptiongroup==1.2.2
      - iniconfig==2.1.0
      - packaging==24.2
      - pluggy==1.5.0
      - pytest==8.3.5
      - tomli==2.2.1
prefix: /opt/conda/envs/astor

tests/test_code_gen.py::CodegenTestCase::test_empty_iterable_literals
tests/test_code_gen.py::CodegenTestCase::test_annassign tests/test_code_gen.py::CodegenTestCase::test_arguments tests/test_code_gen.py::CodegenTestCase::test_complex tests/test_code_gen.py::CodegenTestCase::test_comprehension tests/test_code_gen.py::CodegenTestCase::test_del_statement tests/test_code_gen.py::CodegenTestCase::test_dictionary_literals tests/test_code_gen.py::CodegenTestCase::test_docstring_function tests/test_code_gen.py::CodegenTestCase::test_docstring_method tests/test_code_gen.py::CodegenTestCase::test_inf tests/test_code_gen.py::CodegenTestCase::test_multiple_call_unpackings tests/test_code_gen.py::CodegenTestCase::test_nan tests/test_code_gen.py::CodegenTestCase::test_pow tests/test_code_gen.py::CodegenTestCase::test_right_hand_side_dictionary_unpacking tests/test_code_gen.py::CodegenTestCase::test_slicing tests/test_code_gen.py::CodegenTestCase::test_try_expect tests/test_code_gen.py::CodegenTestCase::test_tuple_corner_cases tests/test_code_gen.py::CodegenTestCase::test_unary tests/test_code_gen.py::CodegenTestCase::test_unicode_literals tests/test_code_gen.py::CodegenTestCase::test_yield
tests/test_code_gen.py::CodegenTestCase::test_async_comprehension tests/test_code_gen.py::CodegenTestCase::test_async_def_with_for tests/test_code_gen.py::CodegenTestCase::test_class_definition_with_starbases_and_kwargs tests/test_code_gen.py::CodegenTestCase::test_compile_types tests/test_code_gen.py::CodegenTestCase::test_docstring_class tests/test_code_gen.py::CodegenTestCase::test_docstring_module tests/test_code_gen.py::CodegenTestCase::test_double_await tests/test_code_gen.py::CodegenTestCase::test_elif tests/test_code_gen.py::CodegenTestCase::test_fstring_trailing_newline tests/test_code_gen.py::CodegenTestCase::test_fstrings tests/test_code_gen.py::CodegenTestCase::test_imports tests/test_code_gen.py::CodegenTestCase::test_matrix_multiplication tests/test_code_gen.py::CodegenTestCase::test_non_string_leakage tests/test_code_gen.py::CodegenTestCase::test_output_formatting tests/test_code_gen.py::CodegenTestCase::test_pass_arguments_node tests/test_code_gen.py::CodegenTestCase::test_with
astor/code_gen.py docs/changelog.rst
astor/code_gen.py docs/changelog.rst