KEMBAR78
`ssl.SSLContext` type hint shouldn't have an `__init__` method, only `__new__` · Issue #8632 · python/typeshed · GitHub
Skip to content

ssl.SSLContext type hint shouldn't have an __init__ method, only __new__ #8632

@tifv

Description

@tifv

stdlib/ssl.pyi currently contains a definition for ssl.SSLContext.__init__() with the protocol argument. But the actual type in stdlib does not define __init__() at all, only __new__().

On attempting to subclass SSLContext while overriding only __new__() method (with another set of arguments) type checker will incorrectly show an error (incompatibility between constructors). On the other hand, when overriding both __new__() and __init__() and calling super().__init__(protocol), type checker will not complain, though the code will in fact produce a TypeError: object.__init__() takes exactly one argument (the instance to initialize) at runtime.

Would it be correct to remove __init__ definition from SSLContext class, leaving only __new__? I have edited the local typeshed copy that pylance uses on my computer and it seems to work (removes the error in the first case and shows an error in the second).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions