Skip to content

pyrefly coverage reports optional imports not used in stubs as untyped #3773

Closed

Description

@jorenham

In numpy/f2py/crackfortran.py (src):

try:
    import charset_normalizer
except ImportError:
    charset_normalizer = None

In the corresponding .pyi there is no such import, because there's simply no need for it.

Yet, pyrefly coverage check (pyrefly==1.1.0.dev2) reports

 WARN `numpy.f2py.crackfortran.charset_normalizer` is untyped [coverage-missing]
   --> numpy/f2py/crackfortran.py:155:5
    |
155 |     charset_normalizer = None
    |     ------------------
    |

But I don't think that annotating charset_normalizer as None | ModuleType is needed, and it might even confuse some type-checkers. So I think that pyrefly coverage shouldn't report optional imports like these ones. This is a very common pattern, after all.

Activity

  1. jorenham commented on Jun 11, 2026

    @jorenham
    CollaboratorAuthor

    Also, dibs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions