News for hackers. Stuff that matters.
Re:What's New in Python 3.11? by RugnirViking on Monday June 27, 2022 @03:30AM (#31891593)
my main issue with the typing is circular imports, and how ultimately for a lot of configurations the best solution is to just skip the typing that one time. Even "if type_checking:" often simply can't cut it

I want to be able to use typing everywhere if I'm going to use it, it really grinds when I have to selectively not use it.

That being said, im glad typing is in the language :)

Re:What's New in Python 3.11? by kortex on Monday June 27, 2022 @08:57AM (#31893923)
Configuration hoisting and library layout to avoid circulars is tricky. The way I structure my libs, lets say ./foo is my main lib, I'll have ./foo/types/.py with most of my primary schema models (I use Pydantic heavily). Then ./foo/config/.py manages application config. Basically everything is pulled in with env vars / config files - I rarely use CLI flags for application-level global configuration - the rest are passed in to entry point functions.

What this means is I can import my AppConfig class anywhere (except types and config submodules) without circular imports, construct them, and they will be initialized with the configs from the env.

Occasionally I have to bust out ForwardRef annotations and model.update_forward_refs() but that's pretty rare. Basically, the imports are structured so that it's as close to a DAG as possible.

Definitely check out pydantic, it makes it really easy to do 12-factor style application config.

I haven't done a lot with CLI-flag global config, but if I had to, I'd use something like dependency-injectors to wire it all together.

Re:What's New in Python 3.11? by kzrdude on Monday June 27, 2022 @05:15AM (#31892228)
The official solution to this is to just use strings. I.e instead of Type, use "Type" where Type can't be in scope because of circularity.
Re:What's New in Python 3.11? by selcuka on Monday June 27, 2022 @03:40AM (#31891655)
> my main issue with the typing is circular imports

FYI: You can use strings as a workaround, or the

    from __future__ import annotations
trick.