-
-
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
Conversation
9fef2d4
to
d47609d
Compare
Accomplish this by using a mapping that doesn't collide on valid python identifiers. We map '.' to '___' and the (rare and unlikely, but possible) '___' to '_3___'. (This collides '___' with '.3', which is fine.) This makes naming not reliant on the order of processing things which is important for separate compilation, since it will turn out that most of our "internal" names actually do need to be exported (but we would still like to shorten the module name part). I also like the output better, even though it is a little more verbose, since it makes it obvious what is a module seperator and what is an underscore.
d47609d
to
7290159
Compare
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.
I agree that it's better to have consistent generated names than the shortest possible one.
@@ -1416,11 +1416,12 @@ def __init__(self, | |||
else: | |||
self.bound_sig = FuncSignature(sig.args[1:], sig.ret_type) | |||
|
|||
@property | |||
def shortname(self) -> str: | |||
return self.class_name + '.' + self.name if self.class_name else self.name |
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
@@ -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 comment
The 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 C.foo
and C___foo
in the same namespace?
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.
I'll add that to the name clash issue test
Accomplish this by using a mapping that doesn't collide on valid
python identifiers. We map
.
to___
and the (rare and unlikely,but possible)
___
to_3___
. (This collides___
with.3
,which is fine.)
This makes naming not reliant on the order of processing things
which is important for separate compilation, since it will turn out
that most of our "internal" names actually do need to be exported
(but we would still like to shorten the module name part).
I also like the output better, even though it is a little more
verbose, since it makes it obvious what is a module separator and what
is an underscore.