Skip to content
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

API for compress_multiple is too restrictive on progress argument #46

Open
devops-dmdx opened this issue Sep 14, 2023 · 0 comments · May be fixed by #47
Open

API for compress_multiple is too restrictive on progress argument #46

devops-dmdx opened this issue Sep 14, 2023 · 0 comments · May be fixed by #47

Comments

@devops-dmdx
Copy link

Hi!

Currently, the progress argument of compress_multiple is checked with PyFunction_Check.

Most of the time, it is fine. But there are cases where this check fails (e.g. partial, or compiled function with Python compiler like SCons).

I guess that any callable would be good for pyminizip right? So why not checking the progress object with PyCallable_Check which has the same signature than PyFunction_Check

int PyFunction_Check(PyObject *o)
Return true if o is a function object (has type PyFunction_Type). The parameter must not be NULL.

vs

int PyCallable_Check(PyObject *o)
Determine if the object o is callable. Return 1 if the object is callable and 0 otherwise. This function always succeeds.

Environment

Python 3.8.10 (tags/v3.8.10:3d8993a, May 3 2021, 11:48:03) [MSC v.1928 64 bit (AMD64)]

Example when passing a compiled function

Type of progress is <class 'compiled_function'>
Exception while creating archive 20230913-203728.zip: progress must be function or None
Traceback (most recent call last):
  File "zipper.py", line 54, in compress
    pyminizip.compress_multiple(
ValueError: progress must be function or None

Example when passing a partial

Type of progress is <class 'functools.partial'>
Exception while creating archive 20230913-204749.zip: progress must be function or None
Traceback (most recent call last):
  File "zipper.py", line 52, in compress
    pyminizip.compress_multiple(
ValueError: progress must be function or None
roddehugo added a commit to roddehugo/pyminizip that referenced this issue Sep 14, 2023
Check the `progress` object with `PyCallable_Check` which has the same signature than `PyFunction_Check`.

> `int PyFunction_Check(PyObject *o)`
> Return true if o is a function object (has type PyFunction_Type). The parameter must not be NULL.

vs

> `int PyCallable_Check(PyObject *o)`
> Determine if the object o is callable. Return 1 if the object is callable and 0 otherwise. This function always succeeds.

This commit closes smihica#46
@roddehugo roddehugo linked a pull request Sep 14, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant