|
|
|
|
|
by joshuamorton
2913 days ago
|
|
>I started to agree with that but then I realized: I don't think you can get getattr to raise an error here at all. The keys are strings, the default value is provided, I don't think there's a fault path here. Of course you can ;) __getattr__ could invoke a network request that fails for all you know. But yes this was more a general comment on this layout. The data-driven layout, while very explicit in code, is actually awful when you encounter issues at runtime, for exactly the reasons you describe. While I'm not a fan of this PEP's syntax, I will say that I do think it someone helps here, it reduces the boilerplate from 3-4 lines in some cases to a single line, which in practice makes this more visually declarative, and keeps tracebacks sane. That said this pattern is rare enough for me that I don't think I'll be using this tool anytime soon. |
|
OMG! Yes, of course, but at that point your traceback has bigger problems. :-)