Skip to content

error: "type" has no attribute "from_private_key" #16153

Closed
@rectalogic

Description

@rectalogic

Bug Report
paramiko keys have base class PKey which has a classmethod from_private_key. When trying to call this on a subclass, mypy errors with:

error: "type" has no attribute "from_private_key"

To Reproduce

import io
from paramiko.dsskey import DSSKey
from paramiko.ecdsakey import ECDSAKey
from paramiko.ed25519key import Ed25519Key
from paramiko.rsakey import RSAKey

for pkey_class in (RSAKey, DSSKey, ECDSAKey, Ed25519Key):
    pkey_class.from_private_key(io.StringIO("hello"))
> python -m venv venv
> venv/bin/pip install mypy==1.5.1 paramiko==3.3.1 types-paramiko==3.3.0.0
> venv/bin/mypy pkey.py
pkey.py:8: error: "type" has no attribute "from_private_key"  [attr-defined]
Found 1 error in 1 file (checked 1 source file)

Actual Behavior

See above. Changing the code to this passes with no error:

import typing as ta
import io
from paramiko.pkey import PKey
from paramiko.dsskey import DSSKey
from paramiko.ecdsakey import ECDSAKey
from paramiko.ed25519key import Ed25519Key
from paramiko.rsakey import RSAKey

key_classes: ta.Sequence[type[PKey]] = (RSAKey, DSSKey, ECDSAKey, Ed25519Key)
for pkey_class in key_classes:
    pkey_class.from_private_key(io.StringIO("hello"))

Your Environment

  • Mypy version used: 1.5.1
  • Mypy command-line flags:
  • Mypy configuration options from mypy.ini (and other config files):
  • Python version used: 3.10.13

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-join-v-unionUsing join vs. using unions

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions