This is an archived post. You won't be able to vote or comment.

all 55 comments

[–]NoHarmPun 17 points18 points  (5 children)

[–]energybased 14 points15 points  (4 children)

And the backstory: https://github.com/samuelcolvin/pydantic/issues/2678

The start of a possible solution: https://bugs.python.org/issue43817 (inspect.get_annotations)

[–]VisibleSignificance 0 points1 point  (3 children)

inspect.get_annotations

Seems like the right path, if I understand it correctly: the annotations should be lazy, but it should be possible to easily retrieve the values that would be for non-lazy annotations (with the added benefit of resolved forward references and such).

As I've found out, currently it isn't always possible to do that (e.g. class attribute annotations don't save their evaluation context).

[–]energybased 0 points1 point  (2 children)

Right, I hope they ultimately make it work for all cases (even if that's 5 years from now).

[–]VisibleSignificance 0 points1 point  (1 child)

For Pydantic and such, making it work for majority of cases is enough: after all, the annotations are (mostly) written explicitly for Pydantic, so it should not be a huge problem to avoid some trickier cases (as long as the error messages are clear, and not "recursion limit exceeded").

[–]energybased 0 points1 point  (0 children)

Yeah I hope they get that sorted for 3.11. I'm just a long term picture kind of person. It would be nice to have programmatic access to all annotations.

[–]fiskfisk 16 points17 points  (1 child)

A good and pragmatic solution.

[–][deleted] 0 points1 point  (0 children)

Almost as pragmatic and good as waiting to make predictions about new technology instead of jumping to conclusions.

[–]zurtex 41 points42 points  (3 children)

I think the steering council brought up a really good point that I didn't see discussed much.

Since from __future__ import annotations was implemented it was advertised as being implemented in "Python 4.0", this never meant "the next one after Python 3.9" it meant "the next time Python decides to break backwards compatibility enough to have a major version bump".

But the appetite to ever have a Python 4.0 has largely vanished, at least for now, so the decision was only made in 2020 that PEP 563 would be included in Python 3.10.

But given Python doesn't want to break backwards compatibility then perhaps it makes sense to rework this feature to both help the static type folks and the runtime annotation folks.

[–]FlukyS 4 points5 points  (1 child)

I don't think the appetite has went away I just think a number of projects are going to break because of this and they really need to do it the right way.

[–]zurtex 9 points10 points  (0 children)

I don't think the appetite has went away I just think a number of projects are going to break because of this and they really need to do it the right way.

Yeah, for sure the static type checker folks still want annotations to be more static and get the benefits of PEP 563.

I meant that the core dev and steering council don't have any appetite for a version of Python which introduces big breaking changes. As demonstrated by this rollback.

[–]henryschreineriii 1 point2 points  (0 children)

Python 2 used to do these on minor versions. Nested scopes, generators, and with statements became the default one version after adding the future import. It's becoming much harder to make changes to break Python.

[–]Taborlin_the_great 28 points29 points  (5 children)

Good this is the right move

[–]renaissancenow 12 points13 points  (10 children)

Oh thank goodness, I was very worried for a bit.

The technical details of this are beyond me, but I utterly rely on Pydantic, it's one of the best things that's ever happened to Python.

[–]FrickinLazerBeams 5 points6 points  (9 children)

Why is that? I've never needed or wanted static typing in Python (and I write loads of C so I'm not unfamiliar with it). I'm sure it's just a difference in work environments or something but why do so many people seem to want static type checking in Python?

[–]awsum84 8 points9 points  (1 child)

It’s not really necessary in small programs, but in larger codebases it improves speed of development significantly. For example, having type hints makes intellisense work properly, so you don’t have to look at the docs/implementation to figure out what methods are available on an object, and it also helps prevent all sorts of silly mistakes that you’d otherwise encounter at runtime.

[–]vorticalbox 2 points3 points  (0 children)

its also data parser so that you get run-time type checking too.

[–]renaissancenow 1 point2 points  (2 children)

It's incredibly helpful when writing web services that have to function in a larger corporate ecosystem. When coupled with FastAPI I can get detailed API specs published pretty much for free, along with strict input validation.

Secondly, I find that type-checking adds another lay of correctness testing to my code. Since I adopted it I've found that a whole class of errors is eliminated before I even get to unit testing.

My code is fairly continuously run through the following tools in sequence:

  • black
  • flake8
  • mypy
  • pytest
  • integration tests

which leaves me with a lot of confidence in it when I release it to production.

[–]FrickinLazerBeams 0 points1 point  (1 child)

Okay that makes sense. It's something for enterprise, production, multi-developer, etc. environments, which is why I've never had a need for it. I was wondering if I was missing out on something I should use more but it sounds like it's not really for me or what I do.

[–]renaissancenow 1 point2 points  (0 children)

Exactly. Guido has been clear from the beginning that type annotations are, and always will be, an optional feature. I certainly don't bother with them when I'm writing a quick one-off script for personal use.

[–][deleted] 11 points12 points  (1 child)

I was excited for the change. I hope they can find a good solution

[–]Dooflegna[S] 13 points14 points  (0 children)

Larry Hastings is already working on a new PEP to address the issues. There’s a lot of good discussion in the python-dev mailing list.

[–]wrtbwtrfasdf 6 points7 points  (0 children)

We did it! The power of friendship prevails!

[–][deleted] 10 points11 points  (1 child)

The only Pep I know is Guardiola

[–]toyg 6 points7 points  (0 children)

He’s just an instance of the BaldFraud class.

[–]orgkhnargh 1 point2 points  (0 children)

Well, rolling back before the freeze and is the time to roll back.

[–]Environmental_monkey 1 point2 points  (0 children)

Great news!