support strings as type annotations #73

Closed
opened 2021-11-05 17:23:00 +08:00 by sb10q · 6 comments
There is no content yet.
sb10q added the
low-priority
label 2021-11-20 11:03:40 +08:00
ychenfo was assigned by sb10q 2021-11-20 11:03:48 +08:00
Poster
Owner

The whole forward reference / string type annotations business seems a bit messy for now, and in flux in Python...

From https://docs.python.org/3/library/typing.html:

Note
get_type_hints() does not work with imported type aliases that include forward references. Enabling postponed evaluation of annotations (PEP 563) may remove the need for most forward references. 
Note
PEP 585 generic types such as list["SomeClass"] will not be implicitly transformed into list[ForwardRef("SomeClass")] and thus will not automatically resolve to list[SomeClass]. 

The latest on the topic seems to be https://www.python.org/dev/peps/pep-0649/.
Let's table this for now and when the time comes see what Python decided. If PEP649 is adopted, patching our Python to enable it without waiting for a release is fine.

The whole forward reference / string type annotations business seems a bit messy for now, and in flux in Python... From https://docs.python.org/3/library/typing.html: ``` Note get_type_hints() does not work with imported type aliases that include forward references. Enabling postponed evaluation of annotations (PEP 563) may remove the need for most forward references. ``` ``` Note PEP 585 generic types such as list["SomeClass"] will not be implicitly transformed into list[ForwardRef("SomeClass")] and thus will not automatically resolve to list[SomeClass]. ``` The latest on the topic seems to be https://www.python.org/dev/peps/pep-0649/. Let's table this for now and when the time comes see what Python decided. If PEP649 is adopted, patching our Python to enable it without waiting for a release is fine.

Is this done?

Is this done?
Collaborator

Is this done?

Not yet. There seems to be not much progress on this on how Python will resolve this.

> Is this done? Not yet. There seems to be not much progress on this on how Python will resolve this.
sb10q removed the
low-priority
label 2022-02-28 15:53:51 +08:00
Poster
Owner

This may be causing problems for the phaser driver (Phaser.channel, PhaserChannel.phaser, PhaserChannel.oscillator attributes)

This may be causing problems for the phaser driver (``Phaser.channel``, ``PhaserChannel.phaser``, ``PhaserChannel.oscillator`` attributes)
Poster
Owner

I guess we can simply solve those with from __future__ import annotations into the Phaser driver (https://www.python.org/dev/peps/pep-0563/). NAC3 itself isn't affected by this problem as it has its own parser and resolver for type annotations (correct?) and the CPython annotation data is rarely used.

I guess we can simply solve those with ``from __future__ import annotations`` into the Phaser driver (https://www.python.org/dev/peps/pep-0563/). NAC3 itself isn't affected by this problem as it has its own parser and resolver for type annotations (correct?) and the CPython annotation data is rarely used.
Poster
Owner

Seems to work fine and is probably the simplest and best way to solve this problem for now.

Seems to work fine and is probably the simplest and best way to solve this problem for now.
sb10q closed this issue 2022-02-28 16:55:38 +08:00
Sign in to join this conversation.
No Milestone
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: M-Labs/nac3#73
There is no content yet.