#Mypy

2025-12-18

I have been investigating this:
```Python
from numbers import Real
def positive(x: Real) -> bool:
return x > 0 # Type Check failed!
```

#PEP 484 said that one should use `float` instead, but this does not solve for other numerical types e.g. #GMP numbers or #NumPy numbers.

And I found some old threads like github.com/python/typing/issue
github.com/python/mypy/issues/
discuss.python.org/t/numeric-g
discuss.python.org/t/clarifyin

And it seems like none has make any real progress.

To my understanding, ABC should also provides a good protocol for typing, just like typeclasses in #Haskell.

#Python #Typing #MyPy #Pyright

N-gated Hacker Newsngate
2025-12-16

🚀🎉 Hold onto your keyboards, folks! has unleashed "ty," a lightning-fast , because, of course, we needed another one. Written in , because Python apparently wasn't fast enough for checking itself, "ty" is now in and ready to bravely enter a market already saturated with the likes of , , and other tools you didn't know you couldn't live without. 🌪️🔧
astral.sh/blog/ty

2025-11-12

I have a script called pyfix which runs mypy and ruff to

- have strong typing
- have a fixed and orderly import order
- have the file always formatted in the same way
- detect programming errors and redundancies.

Now I am working on gitlogui (codeberg.org/harald/gitlogui) the main script of which I called glu. So I am running

pyfix glu

all the time, which reads funny. 😀

#python #gitlogui #mypy #ruff #strongTyping #linting

Charles Tapley Hoytcthoyt@scholar.social
2025-10-03

have you ever annotated a TypedDict onto the **kwargs fuction and want Sphinx to automatically add it to the function's docstring?

class GreetingKwargs(TypedDict):
name: Annotated[str, Doc("the name of the person to greet")]

def greet(**kwargs: Unpack[GreetingKwargs]):
"""Greet a person.

:returns: A nice greeting
"""
return f"hello, {kwargs['name']}!"

i wrote a plugin for it github.com/cthoyt/sphinx-unpack

#python #sphinx #mypy #typing

Automatically generated documentation
2025-10-02

Python type-checkers should infer Final from all-caps named variables. github.com/python/mypy/issues/ Consider adding a thumb up :) #python #typing #mypy

MAX_SIZE = 9000
MAX_SIZE += 1  # Error reported by type checker
# (code snippet that illustrates the idea)
2025-09-29

Introducting: `stormcheck mypy --edu` , type check your code, and learn #Python fundamentals at the same time!

The error messages themselves are ordered by difficulty level, and each category has a dedicated tutorial built-in to the CLI!

My goal was to create a tool that can teach beginners as they work, but still be useful to professionals who already know their craft.

We call this Compassion-Driven-Development

Once finished, I plan on putting this on all my open-source projects to help contributors who are new to Python.

Soon: RUFF checking as well?? What else would a tool like this benefit from?

#OpenSource #CLI #mypy #education #programming #teaching #learning

2025-09-24

I have a Python static typing conundrum. I'd like a solution that works with mypy.

I have a function which fills out a list, albeit not "in order", so it's inconvenient to write it as a list comprehension or similar.

So, I fill the list with [None] and assert that all the Nones are gone by the time it returns.

However, the assertion I wrote does NOT convince mypy that the type of result now matches the return type of f, and I get a diagnostic: Incompatible return value type (got "list[int | None]", expected "list[int]")

def f() -> list[int]:
result: list[int|None] = [None] * 3
result[0] = 1
result[2] = 2
result[1] = 3
assert not any(i is None for i in result)
return result

Any hints? Can I do something besides cast the return value?

Solution: I used TypeGuard (python 3.10+) as suggested in replies. I can accept the runtime overhead.

#askMastodon #python #mypy #answered

Luke T. Shumakerlukeshu@social.coop
2025-08-16

At this point, I think writing #Python without #mypy --strict is insane.

And a side-effect is that if you add a new dependency, there's a solid chance you have to spend a day writing stubs for it. Helps keep bloat down and also means you get a decent tour of the library.

Glyphglyph
2025-08-04

Okay, so, fans of the help me out here:

I am mucking around with writing a simple new thing that, in order to have type annotations that aren't *completely* useless, needs to deal with the fact that Protocol and Factory aren't annotated.

But adding annotations makes the entire framework notice that the pattern of paired-Protocol-and-Factory subclasses are inherently LSP violations, because .protocol and .factory are writable attributes and thus invariant.

2025-08-03

The pythonbuilder got a few improvements. Apart from introducing ruff as a consistent python code formatter and for linting in addition to mypy, it got a new module pbpython.py which wraps

- ruff check
- ruff format
- mypy

calls for easy use as target builders.

codeberg.org/harald/pythonbuil

#pythonbuilder
#buildmachine
#bashbuilder
#buildsystem
#buildtool
#softwaredevelopment
#programming
#python
#ruff
#mypy

2025-07-31

I have been addicted to #mypy type checking my #python projects over the last week. After creating several helper scripts for the process of getting from >1000 errors to 0, I am working on making a centralized library to #opensource !

If you use the `--edu` flag, the system will show you educational guidance, and also showcase tutorials that are built-in to the CLI! (That feature isn't in yet, but I am excited to build it)

All of the lessons I have learned from making my projects MyPy Compliant, I hope I can use this tool to teach others, and also help myself with all my future Python Projects!

#programming #development

sumanthvepasumanthvepa
2025-07-16

I'm familiar with s in , but just recently discovered classes in . Like in they allow for structural subtyping. Now you can require that a parameter passed to a function must conform to a given protocol and will statically check that for you. You get the best of both worlds -- the safety of static typing and the convenience of duck typing.

peps.python.org/pep-0544/

Hacker Newsh4ckernews
2025-06-27
2025-06-24

Redid my #neovim config to keep up with the times (I used many deprecated
plug-ins, and didn't use #lua).

I haven't the faintest idea what I'm doing, I just followed a tutorial, got #lazyVim, and a few plug-ins, and I am utterly stomped by how to set up the #python lsp, especially as I want to include #mypy type checking.

The duality of #documentation is that I either get a tutorial that explains nothing and expects you to copy paste, or a manual that goes waaaay over my head.

Anyone else think that the Union type annotation in Python is a code smell that something is too loosely defined?
#python #mypy

Kevin Brown-Silvakevin@brown-silva.social
2025-05-18

Other #PyConUS sprints this week:

* #RAPIDSai
* django-simple-deploy and py-bugger
* #PyFyre, #MyPy, and #MyPyC
* MemRay
* #Ruff or Ty from Astral
* #WheelNext
* ci-test / linting-arguments-python

Additionally there will be an "Introduction to Sprints" open space in Room 310 at 6:00 PM.

#PyConUS2025

2025-05-16

@seungjin I write #python code every day, and type hints are a "syntactic sugar" and are not required at all from the interpreter point of view.

For large projects, it's useful to add hints to "follow" what you are doing, and type checkers like #pyright or #mypy can help to find some bugs, by example when calling a method with wrong parameters types.

It also help for the readability of the code.

Matthew Martinmistersql
2025-05-07

- but mypy already compiles itself to c via so being faster isn't what I'd be expecting, it will be different and probably find different typing errors since for all the type checkers, it comes down to a matter of opinion. Do you think that will be a runtime error? That's in the future, who knows man.

Client Info

Server: https://mastodon.social
Version: 2025.07
Repository: https://github.com/cyevgeniy/lmst