Skip to content

False positive when using os.PathLike in an isinstance check. #4681

@domdfcoding

Description

@domdfcoding

Bug Report

Take, for example. the following code:

import os, pathlib
print(isinstance(pathlib.Path(), os.PathLike))

Since version 0.790 mypy fails with the following error:

domdf@ryzen:~/Python$ mypy mypy_os_pathlike.py 
mypy_os_pathlike.py:2: error: Only @runtime_checkable protocols can be used with instance and class checks
Found 1 error in 1 file (checked 1 source file)

To Reproduce

  1. Analyse the above source with mypy 0.790

Expected Behavior

With mypy 0.782 everything was OK:

domdf@ryzen:~/Python$ mypy mypy_os_pathlike.py 
Success: no issues found in 1 source file

From what I can tell, os.PathLike is not a Protocol but an abc.ABC, so I'm not sure why mypy thinks it is.

Actual Behavior

mypy thinks os.PathLike is a Protocol that cannot be used in isinstance checks.

Your Environment

  • Mypy version used: 0.790
  • Mypy command-line flags: None
  • Mypy configuration options from mypy.ini (and other config files): None
  • Python version used: Python 3.8
  • Operating system and version: Ubuntu 20.04

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