Replies: 3 comments
-
Yes, that should be possible with some manual work, and it's documented in patches across the internet... But let's try to improve that😁 If you can share a link to your module, I can add the docs somewhere once we have the process. |
Beta Was this translation helpful? Give feedback.
-
Hi Jos, The library is found here: HT16K33 ht16k33.py Thoughts on how we proceed? |
Beta Was this translation helpful? Give feedback.
-
A quick step by step that you can follow :
the resulting strcture should be something like this
This also installs tools that are helpfull
I my experience before running pyright --createstubs, first check if the provided code can pass a basic type check by runnin pyright on the code `` If it fails, you can still create stubs, but you may need to change both the stubs and the code later. cd src
pyright --createstub ht16k33 This will create a folder You can commit the If the source did not contain type information or docstrings, you will need to add them manually to the you can refer to both the standard python types and classes ( int , str, float ) and the MicroPython types ( machine.I2C, machine.Pin, etc ) to add type information to the stubs. If you don't know the type of a variable, you can use Initial basic stub : typings\ht16k33\ht16k33.pyiclass HT16K33:
# ...
HT16K33_GENERIC_DISPLAY_ON = ...
# ...
def __init__(self, i2c, i2c_address) -> None:
...
def set_brightness(self, brightness = ...) -> None:
... with some manual improvementsfrom typing import Literal, TypeAlias
from typeshed impint
from machine import I2C
from _typeshed import Incomplete
_Brightness : TypeAlias = Literal[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
class HT16K33:
# ...
HT16K33_GENERIC_DISPLAY_ON : int = ...
# ...
def __init__(self, i2c:I2C, i2c_address:int) -> None:
...
def set_blink_rate(self, rate:Incomplete = 0) -> None:
...
def set_brightness(self, brightness:_Brightness = 15) -> None:
... |
Beta Was this translation helpful? Give feedback.
-
I use an independent library of about 10 .py files. is it possible to create stubs just for the library and then manually add them to my typings folder so they get handled just like they were "machine" or "network"? if this is already documented somewhere, I apologize for not finding it.
Beta Was this translation helpful? Give feedback.
All reactions