pyglet / pyglet

pyglet is a cross-platform windowing and multimedia library for Python, for developing games and other visually rich applications.
http://pyglet.org
BSD 3-Clause "New" or "Revised" License
1.85k stars 302 forks source link

Type hints #643

Open TomFryers opened 2 years ago

TomFryers commented 2 years ago

Type hints (for use with Mypy among others) can help for writing sound code. There are some tools, such as MonkeyType which may make adding these easier.

benmoran56 commented 2 years ago

Hi Tom,

We have already started adding basic type hints to the public facing APIs in the master (v2.0) branch. It's really just a matter of someone taking on the job. Pull requests would of course be welcome here.

From my personal viewpoint, there is one concern. We do try to support all non-EOL Python versions, and as you probably know some of the earlier typing syntax is really... messy. In the effort to keep things readable and approachable for contributors, it might be better to delay some of the gnarly cases for a later date (when we can take advantage of the cleaner syntax). This is just my personal opinion.

TomFryers commented 2 years ago

Great! I realise it's a lot of work and may take some time, but it's nice to know there's progress being made.

Re early typing syntax, from __future__ import annotations might help. It's supported since 3.7 and converts all type annotations to strings, so nice typing features that don't exist yet (e.g. PEPs 585 and 604) don't raise errors. The future of these stringified annotations is uncertain, but I expect them to last long enough not to be a problem here.

pushfoo commented 1 year ago

I've started on this for fonts & font loading locally, but sidetracked by #810 as a trial run for improving loader code legibility.