Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added tests
  • Loading branch information
chgnrdv committed Oct 19, 2022
commit 48b46a4c5d9b2b4581a7bd9cb380e5c4784c81ab
35 changes: 35 additions & 0 deletions Lib/test/test_imp.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,41 @@ def test_find_and_load_checked_pyc(self):
mod = imp.load_module('mymod', file, path, description)
self.assertEqual(mod.x, 42)

def test_issue98354(self):
# _imp.create_builtin should raise TypeError
# if 'name' attribute of 'spec' argument is not a 'str' instance
Comment thread
chgnrdv marked this conversation as resolved.

create_builtin = support.get_attribute(_imp, "create_builtin")

class FakeSpec:
def __init__(self, name):
self.name = self
spec = FakeSpec("time")
with self.assertRaises(TypeError):
create_builtin(spec)

class FakeSpec2:
name = [1, 2, 3, 4]
spec = FakeSpec2()
with self.assertRaises(TypeError):
create_builtin(spec)

class UnicodeSubclass(str):
pass
class GoodSpec:
name = UnicodeSubclass("sys")
spec = GoodSpec()
bltin = create_builtin(spec)
import sys
self.assertEqual(bltin, sys)

class UnicodeSubclassFakeSpec(str):
def __init__(self, name):
self.name = self
spec = UnicodeSubclassFakeSpec("builtins")
bltin = create_builtin(spec)
import builtins
self.assertEqual(bltin, builtins)

class ReloadTests(unittest.TestCase):

Expand Down