Skip to content

Conversation

@msullivan
Copy link
Collaborator

@msullivan msullivan commented Oct 9, 2019

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.

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.
Copy link
Collaborator

@JukkaL JukkaL left a 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.


@property
def shortname(self) -> str:
return self.class_name + '.' + self.name if self.class_name else self.name
Copy link
Collaborator

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?

Copy link
Collaborator Author

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

def test_candidate_suffixes(self) -> None:
assert candidate_suffixes('foo') == ['', 'foo_']
assert candidate_suffixes('foo.bar') == ['', 'bar_', 'foo_bar_']
assert candidate_suffixes('foo') == ['', 'foo.']
Copy link
Collaborator

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?

Copy link
Collaborator Author

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

@msullivan msullivan merged commit 9614518 into master Oct 10, 2019
@gvanrossum gvanrossum deleted the tweak-mangling branch August 26, 2020 21:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants