-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
allow mypy to use custom stdlib stubs #781
Comments
partially impemented in : 2959e98 |
Hi @Josverl following on from #720 I've done a quick test of the v1.24.1 on my existing project with "patched/hacked stubs for mypu use" but quickly run into blockers that I think are related directly to me using the stubs
I did a terrible job of tracking my changes when I was previously modding my installed stubs typings folder to make it work with mypy, such that now every time I get back to it to attempt to reverse engineer it into clean commits & PR here I don't get very far. Much of the problem is due to me inadvertently allowing vscode and/or black to auto-reformat all the files... so now diff's are very noisy. I've still got an internally tracked task to clean this up properly and submit it, but little foreseable time to get to it so in liew of that I'm going to dump a snapshot here, just in case it helps you at all. Feel free to ignore it if it's more effort than its worth. typings_andrewleech_tgz.zip For context I believe this was originally installed with:
and appears to be from I use pre-commit with Additionally, this was another WIP typings folder I had, also for use as a typeshed dir, but trying to resolve #720 in a different way. |
Thanks for sharing. I run all all typecheck tests with the same config exclude = [
"typings[\\/].*", # TOML basic string
] I explicitly exclude the wrt to the micropython io , Adding the |
If you want to submit changes , then the best angle is to target (but note that mypy does not like some of the modules there, so be ready to rename sys and collections) |
V1.19.1.post9compared with : Added / changed /:
V1.21.0 (.mod)compared with: note: the re-install of stdlib is slightly different - while it does have the same version, perhaps changes were copied over from an earlier version Added / changed /:
these are the diffs , ruff format on both sides to get rid of some noise, and leaving out the async patches and some metadata changes_v1.19.1.patch If you can still remember why you made which changes, that would help me decide what and how to integrate these in the stub project. |
…ence and stdlib stubs partly resolves : #781 Signed-off-by: Jos Verlinde <[email protected]>
…arameter handling partial : Josverl/micropython-stubs#781 Signed-off-by: Jos Verlinde <[email protected]>
io.Stream is a Protocol in MicroPython. so it probably should be typed as a Protocol class Stream(Protocol):
"""
MicroPython stream protocol. Due to implementation mechanism
not all methods are guaranteed to be available on all classes
based on the stream type / protocol.
"""
def __init__(self, *argv, **kwargs) -> None: ...
def __enter__(self: Self) -> Self: ...
def __exit__(
self,
exc_type: type[BaseException] | None,
exc_val: BaseException | None,
exc_tb: TracebackType | None,
) -> None: ...
def close(self) -> None: ...
def flush(self) -> None: ...
def read(self, __size: int | None = ...) -> bytes: ...
def read1(self, __size: int = ...) -> bytes: ...
def readinto(self, __buffer: WriteableBuffer) -> int: ...
def readline(self, __size: int | None = ...) -> bytes: ...
def readlines(self, __hint: int = ...) -> list[bytes]: ...
def seek(self, __offset: int, __whence: int = ...) -> int: ...
def tell(self) -> int: ...
def write(self, __buffer: ReadableBuffer) -> int: ...
def write1(self, __buffer: ReadableBuffer) -> int: ... |
code optimisations to build.py script #781 Signed-off-by: Jos Verlinde <[email protected]>
in a Q&D test it is possible to allow mypy to use the
new 1.24.1 stubs ( that omit sys)
mypy --custom-typeshed-dir ./typings .
by adding :
typings\mypy_extensions.pyi
origin : typestub repo :
stubs\mypy-extensions\mypy_extensions.pyi
PyPI : types-mypy-extensions
refs:
await asyncio.sleep_ms(4) # stubs-ignore: linter == "mypy"
key = sec_type, bytes(key) # stubs-ignore: linter == "mypy"
tasks[x] = asyncio.create_task(bar2(x)) # stubs-ignore: linter=="mypy"
await asyncio.sleep_ms(200 * n) # Pause by varying amounts # stubs-ignore: linter=="mypy"
s = asyncio.StreamReader(sys.stdin) # stubs-ignore: linter=="mypy"
hist = [] * _HISTORY_LIMIT # stubs-ignore: linter=="mypy"
cmd # stubs-ignore: linter=="mypy"
sys.stdout.write(b) # stubs-ignore: linter=="mypy"
sys.stdout.write(b) # stubs-ignore: linter=="mypy"
sys.stdout.write(cmd) # stubs-ignore: linter=="mypy"
self.swriter = asyncio.StreamWriter(self.uart, {}) # stubs-ignore: linter=="mypy"
self.sreader = asyncio.StreamReader(self.uart) # stubs-ignore: linter=="mypy"
await self.swriter.awrite( # stubs-ignore: linter=="mypy"
await asyncio.sleep_ms(300) # stubs-ignore: linter=="mypy"
self.swriter = asyncio.StreamWriter(self.uart, {}) # stubs-ignore: linter=="mypy"
self.sreader = asyncio.StreamReader(self.uart) # stubs-ignore: linter=="mypy"
await self.swriter.awrite("{}\r\n".format(command)) # stubs-ignore: linter=="mypy"
await asyncio.sleep_ms(0) # stubs-ignore: linter=="mypy"
s.write(b"GET / HTTP/1.0\r\n\r\n") # stubs-ignore: linter == "mypy"
print(s.read()) # stubs-ignore: linter == "mypy"
ar = array.array("I", [0 for _ in range(NUM_LEDS)]) # stubs-ignore: linter == "mypy"
buffer_1 = io.StringIO(alloc_size) # stubs-ignore: version<=1.18.0 or linter == "mypy"
buffer_2 = io.BytesIO(alloc_size) # stubs-ignore: version<=1.18.0 or linter == "mypy"
buf = io.BufferedWriter(stream, 8) # stubs-ignore: linter == "mypy"
buffer_1 = uio.StringIO(alloc_size) # stubs-ignore: linter == "mypy"
buffer_2 = uio.BytesIO(alloc_size) # stubs-ignore: linter == "mypy"
from sys import print_exception # stubs-ignore: linter == "mypy"
sys.print_exception(exc) # stubs-ignore: linter == "mypy"
previous = sys.atexit(byebye) # stubs-ignore: linter == "mypy"
The text was updated successfully, but these errors were encountered: