Skip to content

Type name cannot contain surrogates #4786

Description

@DimitrisJim

Issue caught after an update to test_builtins in #4765. Creating a new type and supplying as a name a value that contains a surrogate (in this case \udcdc is used) should result in an error.

RustPython:

>>> type("A\udcdcB", (), {})
>>> <class '__main__.A�B'>

While in CPython:

>>> type("A\udcdcB", (), {})
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'utf-8' codec can't encode character '\udcdc' in position 1: surrogates not allowed

Activity

  1. added
    C-bugSomething isn't working
    C-compatA discrepancy between RustPython and CPython
    on Mar 27, 2023
  2. youknowone commented on Mar 28, 2023

    @youknowone
    Member

    depending on non-utf8 string support

  3. JazzGlobal commented on May 1, 2023

    @JazzGlobal
    Contributor

    Rust noob here. Is this discrepancy caused by how Rust handles char and String versus a language like C#?

    EDIT: My reasoning for the above question is due to Rust supporting things like 🚀

  4. youknowone commented on Oct 6, 2026

    @youknowone
    Member

    The originally reported problem no longer reproduces on current main. Closing per the recheck in #8982.

    — commented by Grok 4.6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugSomething isn't workingC-compatA discrepancy between RustPython and CPython

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions