Skip to content

Mypy does not accept mmap object in re.match #1467

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
libre-man opened this issue Jul 6, 2017 · 5 comments
Closed

Mypy does not accept mmap object in re.match #1467

libre-man opened this issue Jul 6, 2017 · 5 comments
Labels
stubs: false positive Type checkers report false errors

Comments

@libre-man
Copy link
Contributor

It seems that the re.compile types are to restrictive, the following code errors in mypy but running it is no problem:

# _txt_fmt is a object gotten from `re.compile`
with open(file, 'r+') as f:
    with mmap.mmap(f.fileno(), 0) as data:
        match = _txt_fmt.match(data)

Mypy gives the error Argument 1 to "match" of "Pattern" has incompatible type "mmap"; expected "bytes".

@srittau
Copy link
Collaborator

srittau commented Sep 11, 2018

Full example:

import mmap
import re

with open("...", 'r+') as f:
    with mmap.mmap(f.fileno(), 0) as data:
        match = re.compile(b"").match(data)

The mmap documentation explicitly mentions the interaction with re: "You can use mmap objects in most places where bytearray are expected; for example, you can use the re module to search through a memory-mapped file." So I believe we should fix this.

@pavel-kalmykov
Copy link

Hello. Any update on this?

@srittau
Copy link
Collaborator

srittau commented Aug 11, 2021

PR welcome!

@itaisteinherz
Copy link
Contributor

I'd like to work on this.

@JelleZijlstra
Copy link
Member

Should be fixed with #7679.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stubs: false positive Type checkers report false errors
Projects
None yet
5 participants