skia-python / skia-python/skia-python

Paint.setXYZ methods doesn't accept nullptr (None)

Open
#156 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Jupyter Notebook
Stars
323
Forks
52
Avg merge
2h 29m
Merged PRs (30d)
1

Description

Describe the bug
Several setter methods of skia.Paint are documented to accept nullptr to remove the filter/effect from the paint. However, this is not the case as passing None to these methods throws a type error. This is because these methods are pybind-ed with a lambda function. The methods listed below have this problem.

To Reproduce
Steps to reproduce the behavior:
Run the following code

import skia

paint = skia.Paint(
    ImageFilter=skia.ImageFilters.Blur(1.0, 1.0),
    ColorFilter=skia.LumaColorFilter.Make(),
    MaskFilter=skia.MaskFilter.MakeBlur(skia.kNormal_BlurStyle, 1.),
    PathEffect=skia.DashPathEffect.Make([2., 1.], 0),
    Shader=skia.Shaders.Empty(),
)

print(paint.getImageFilter())  # prints <skia.ImageFilter object at 0x...>
paint.setImageFilter(None)  # this works
print(paint.getImageFilter())  # prints None

paint.setColorFilter(None)  # fails with TypeError: setColorFilter(): incompatible function arguments. The following
                            # argument types are supported: # 1. (self: skia.Paint, colorFilter: SkColorFilter) -> None
paint.setMaskFilter(None)  # fails with TypeError
paint.setPathEffect(None)  # fails with TypeError
paint.setShader(None)  # fails with TypeError

Expected behavior
Each of these methods should accept None, execute without error, and remove the corresponding filter/effect.

Desktop (please complete the following information):

  • OS: Ubuntu 20.04.1 LTS
  • Python: 3.8
  • skia-python version: 87.3

Additional context
Note that paint.setImageFilter(None) works as expected. This is because setImageFilter is not pybind-ed with a lambda function.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the pybind lambda bindings for Paint.setColorFilter, setMaskFilter, setPathEffect, and setShader, comparing them with setImageFilter, which already accepts None. Reproduce the issue with the provided Python example, then verify that each listed setter accepts None and removes its filter or effect without a type error.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
computer-graphics
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.