Skip to content

Frozen "trackback" and "typing" raise TypeError in deepfreeze.py #94773

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
MidCheck opened this issue Jul 12, 2022 · 2 comments
Closed

Frozen "trackback" and "typing" raise TypeError in deepfreeze.py #94773

MidCheck opened this issue Jul 12, 2022 · 2 comments
Assignees
Labels
3.11 only security fixes 3.12 only security fixes type-bug An unexpected behavior, bug, or error

Comments

@MidCheck
Copy link

MidCheck commented Jul 12, 2022

Bug report
After adding "traceback" and "typing" modules to freeze_modules.py, "sorted" will raise TypeError when compiling.

def generate_frozenset(self, name: str, fs: FrozenSet[object]) -> str:
    ret = self.generate_tuple(name, tuple(sorted(fs)))
    self.write("// TODO: The above tuple should be a frozenset")
    return ret

Frozen "traceback" raise:

TypeError: '<' not supported between instances of 'int' and 'NoneType'

Frozen "typing" raise:

TypeError: '<' not supported between instances of 'str' and 'NoneType'

After that I printed fs:

try:
    ret = self.generate_tuple(name, tuple(sorted(fs)))
except TypeError:
    print(f"name: {name}, fs: {fs}")
    raise

"traceback" and "typing" are output as follows

name: traceback_toplevel_consts_46_consts_14_consts_9, fs: frozenset({None, 0})
name: typing_toplevel_consts_112_consts_1, fs: frozenset({None, 'functools', 'abc'})

I don't understand what the sorted does in the Frozen module here.

Finally, I used a temporary method to unsort these two FrozenSet in the exception handling, and successfully passed the compilation.

def generate_frozenset(self, name: str, fs: FrozenSet[object]) -> str:
    try:
        ret = self.generate_tuple(name, tuple(sorted(fs)))
    except TypeError:
        if name == 'traceback_toplevel_consts_46_consts_14_consts_9' or \
                name == 'typing_toplevel_consts_112_consts_1':
            ret = self.generate_tuple(name, tuple(fs))
        else:
            raise
    self.write("// TODO: The above tuple should be a frozenset")
    return ret

Environment
I checkout v3.11.0b4 after cloning, use Ubuntu 22.04 LTS, arch is x86_64.

@MidCheck MidCheck added the type-bug An unexpected behavior, bug, or error label Jul 12, 2022
@tiran tiran self-assigned this Jul 12, 2022
@tiran tiran added 3.11 only security fixes 3.12 only security fixes labels Jul 12, 2022
@tiran
Copy link
Member

tiran commented Jul 12, 2022

The type error originates from code

def _allow_reckless_class_checks(depth=3):
    return _caller(depth) in {'abc', 'functools', None}

We sort sets to ensure a stable order of entries. It appears we have not encountered sets with mixed, unsortable types yet.

miss-islington pushed a commit to miss-islington/cpython that referenced this issue Jul 12, 2022
…ythonGH-94775)

(cherry picked from commit 0c66074)

Co-authored-by: Christian Heimes <christian@python.org>
miss-islington added a commit that referenced this issue Jul 12, 2022
)

(cherry picked from commit 0c66074)

Co-authored-by: Christian Heimes <christian@python.org>
@tiran
Copy link
Member

tiran commented Jul 12, 2022

The problem is now fixed in 3.11 and main branch.

@tiran tiran closed this as completed Jul 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.11 only security fixes 3.12 only security fixes type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants