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

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

@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.

#ty #mypy - but mypy already compiles itself to c via #mypyc 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.

anyone have some time to help me with a tricky #python #typing and #mypy problem?

it's fully self-contained in https://github.com/cthoyt/python-typing-dilemma. It contains some examples of things I tried, and why they didn't work

it hinges on using PEP-696 defaults in typing.TypeVar, introduced in Python 3.13

GitHub - cthoyt/python-typing-dilemma

Contribute to cthoyt/python-typing-dilemma development by creating an account on GitHub.

GitHub
Our of the box, #pyright is "better" than #mypy . Less configuration and more strict!
ok, a whole day of programming #Python with #mypy and #ruff.

this is much better than without, and ruff is very fast, but mypy is slooooow.

Also, the type system just isn't all that good

I’m busy re-applying this “gradual import” technique on a client project today. Will slowly get them up to a full django-stubs installation.

#Python #MyPy

https://adamj.eu/tech/2022/08/23/python-type-hints-gradually-add-types-for-third-party-packages/

Python Type Hints: How to Gradually Add Types for Third Party Packages - Adam Johnson

Hynek Schlawack recently described graduality as Python’s super power: the ability to prototype in the REPL, and gradually add linting, type checking, and other practices to refine your code into maintainable, production-ready software. You can also apply graduality within tools, activating checks one at a time and fixing the resulting errors as you go.

Nous avons tous nos bonnes pratiques lorsqu'il s'agit de créer un nouveau #projet #Python, avec l'utilisation de patterns et d'outils éprouvés : lint avec #ruff et #mypy, hooks avec #precommit, tests avec #pytest, intégration continue #githubactions : https://github.com/neubig/starter-repo

Libre à chaque personne de faire évoluer le porojet selon ses propres goûts et contraintes.

GitHub - neubig/starter-repo: An example starter repo for Python projects

An example starter repo for Python projects. Contribute to neubig/starter-repo development by creating an account on GitHub.

GitHub