-
-
Notifications
You must be signed in to change notification settings - Fork 3k
[mypyc] Make namegen not need to use suffixes to disambiguate #7676
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,33 +7,34 @@ | |
|
||
class TestNameGen(unittest.TestCase): | ||
def test_candidate_suffixes(self) -> None: | ||
assert candidate_suffixes('foo') == ['', 'foo_'] | ||
assert candidate_suffixes('foo.bar') == ['', 'bar_', 'foo_bar_'] | ||
assert candidate_suffixes('foo') == ['', 'foo.'] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it be useful to have an end-to-end test case that has things like triple underscores in names and possible name clashes, such as having names There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll add that to the name clash issue test |
||
assert candidate_suffixes('foo.bar') == ['', 'bar.', 'foo.bar.'] | ||
|
||
def test_exported_name(self) -> None: | ||
assert exported_name('foo') == 'foo' | ||
assert exported_name('foo.bar') == 'foo___bar' | ||
|
||
def test_make_module_translation_map(self) -> None: | ||
assert make_module_translation_map( | ||
['foo', 'bar']) == {'foo': 'foo_', 'bar': 'bar_'} | ||
['foo', 'bar']) == {'foo': 'foo.', 'bar': 'bar.'} | ||
assert make_module_translation_map( | ||
['foo.bar', 'foo.baz']) == {'foo.bar': 'bar_', 'foo.baz': 'baz_'} | ||
['foo.bar', 'foo.baz']) == {'foo.bar': 'bar.', 'foo.baz': 'baz.'} | ||
assert make_module_translation_map( | ||
['zar', 'foo.bar', 'foo.baz']) == {'foo.bar': 'bar_', | ||
'foo.baz': 'baz_', | ||
'zar': 'zar_'} | ||
['zar', 'foo.bar', 'foo.baz']) == {'foo.bar': 'bar.', | ||
'foo.baz': 'baz.', | ||
'zar': 'zar.'} | ||
assert make_module_translation_map( | ||
['foo.bar', 'fu.bar', 'foo.baz']) == {'foo.bar': 'foo_bar_', | ||
'fu.bar': 'fu_bar_', | ||
'foo.baz': 'baz_'} | ||
['foo.bar', 'fu.bar', 'foo.baz']) == {'foo.bar': 'foo.bar.', | ||
'fu.bar': 'fu.bar.', | ||
'foo.baz': 'baz.'} | ||
|
||
def test_name_generator(self) -> None: | ||
g = NameGenerator(['foo', 'foo.zar']) | ||
assert g.private_name('foo', 'f') == 'foo_f' | ||
assert g.private_name('foo', 'C.x.y') == 'foo_C_x_y' | ||
assert g.private_name('foo', 'C.x.y') == 'foo_C_x_y' | ||
assert g.private_name('foo.zar', 'C.x.y') == 'zar_C_x_y' | ||
assert g.private_name('foo', 'C.x_y') == 'foo_C_x_y_2' | ||
assert g.private_name('foo', 'C_x_y') == 'foo_C_x_y_3' | ||
assert g.private_name('foo', 'C_x_y') == 'foo_C_x_y_3' | ||
assert g.private_name('foo', 'f') == 'foo___f' | ||
assert g.private_name('foo', 'C.x.y') == 'foo___C___x___y' | ||
assert g.private_name('foo', 'C.x.y') == 'foo___C___x___y' | ||
assert g.private_name('foo.zar', 'C.x.y') == 'zar___C___x___y' | ||
assert g.private_name('foo', 'C.x_y') == 'foo___C___x_y' | ||
assert g.private_name('foo', 'C_x_y') == 'foo___C_x_y' | ||
assert g.private_name('foo', 'C_x_y') == 'foo___C_x_y' | ||
assert g.private_name('foo', '___') == 'foo______3_' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this work with nested classes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nothing about mypyc works with nested classes