Last active
September 8, 2018 08:31
-
-
Save mitsuse/b2de5aa71452d8a62c974d11450a1308 to your computer and use it in GitHub Desktop.
A workaround for private __init__ by using name mangling.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
from __future__ import annotations | |
class Foo: | |
class __Internal: | |
pass | |
def __init__(self, _: Type[__Internal]) -> None: | |
pass | |
@staticmethod | |
def empty() -> Foo: | |
return Foo(Foo.__Internal) | |
Foo.empty() # OK | |
Foo(Foo.__Internal) # NG: AttributeError: type object 'Foo' has no attribute '__Internal' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment