fake-bpy-module icon indicating copy to clipboard operation
fake-bpy-module copied to clipboard

Use most recent Python Syntax in .pyi files

Open JonathanPlasse opened this issue 1 year ago • 14 comments

In .pyi files, the most recent syntax of python can be used, as it is only used for static analysis.

Therefore, these changes can be made:

  • [ ] Remove all quotes (future annotation)
  • [x] Use | instead of Optional and Union (PEP 604) (#207)
  • [ ] Use type Parameter Syntax (PEP 695)
  • [x] Use list, dict, … instead of typing.List, typing.Dict, … (PEP 585)
    • [x] builtin (#207)
    • [x] collections.abc (#223)
  • [x] Use Self (PEP 673)
  • [ ] Add Ruff and enable linter rules to avoid regression we encountered (c.f. #222, #224, #296)

I could work on this, to familiarize myself with the codebase.

JonathanPlasse avatar Dec 17 '23 17:12 JonathanPlasse

@JonathanPlasse

Yes, go ahead. Currently, we use Python 3.9 for the generation which does not support these syntax. You many need to change Python version as well. https://github.com/nutti/fake-bpy-module/blob/97f5da91c52f9cab440e16c60cdd1eed5b68329e/.github/workflows/fake-bpy-module-ci.yml#L69

nutti avatar May 12 '24 12:05 nutti

Ok, I will start working on it.

JonathanPlasse avatar May 12 '24 12:05 JonathanPlasse

@JonathanPlasse

#207 is merged now. Will you also tackle the remain (PEP695) as wall?

nutti avatar May 16 '24 12:05 nutti

I will.

JonathanPlasse avatar May 16 '24 13:05 JonathanPlasse

Can I suggest PEP 673's Self type as a related change?

Presently ID.evaluated_get() returns ID, but if this were changed to Self then I believe Object.evaluated_get() would correctly return Object instead of ID.

Unfortunately the documentation just lists the return type as ID, so I don't know if there's anything for the generation code to detect to make this change automatically.

Road-hog123 avatar May 18 '24 14:05 Road-hog123

To avoid regression, we should use the plugin flake-pyi available in Ruff to check we use the modern syntax in the generated code.

JonathanPlasse avatar May 19 '24 17:05 JonathanPlasse

@JonathanPlasse

Should this issue be still opened? I think some features have already merged.

nutti avatar Jun 07 '24 11:06 nutti

Can I suggest PEP 673's Self type as a related change?

Presently ID.evaluated_get() returns ID, but if this were changed to Self then I believe Object.evaluated_get() would correctly return Object instead of ID.

Unfortunately the documentation just lists the return type as ID, so I don't know if there's anything for the generation code to detect to make this change automatically.

This one would be interesting.

To avoid regression, we should use the plugin flake-pyi available in Ruff to check we use the modern syntax in the generated code.

This one would be cool to have.

Is it a problem for you if the issue remains open? Should we open a specific issue for each remaining point instead?

JonathanPlasse avatar Jun 07 '24 11:06 JonathanPlasse

No, I just would like to know the current status and the future plan. We welcome your contribution.

nutti avatar Jun 07 '24 11:06 nutti

I updated the initial comment.

JonathanPlasse avatar Jun 07 '24 12:06 JonathanPlasse

@JonathanPlasse

Ruff linter is now merged to the master branch. You can tackle the remaining task now.

nutti avatar Jul 07 '24 01:07 nutti

@JonathanPlasse

Can I suggest PEP 673's Self type as a related change?

Presently ID.evaluated_get() returns ID, but if this were changed to Self then I believe Object.evaluated_get() would correctly return Object instead of ID.

Unfortunately the documentation just lists the return type as ID, so I don't know if there's anything for the generation code to detect to make this change automatically.

By solving this feature, I solved below item.

  • Use Self (PEP 673)

nutti avatar Jul 20 '24 10:07 nutti

@JonathanPlasse

I think below item seems to have already been resolved by the ruff linter introduced.

  • Add Ruff and enable linter rules to avoid regression we encountered

How do you think about it?

nutti avatar Jul 20 '24 10:07 nutti

Does it check that the generated code passes the rules of flake8-pyi?

JonathanPlasse avatar Jul 20 '24 10:07 JonathanPlasse