<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="de">
	<id>https://tippvomtibb.de/wiki/index.php?action=history&amp;feed=atom&amp;title=HomeAssistant_Programmierung_%28dunder%29_future_%28dunder%29</id>
	<title>HomeAssistant Programmierung (dunder) future (dunder) - Versionsgeschichte</title>
	<link rel="self" type="application/atom+xml" href="https://tippvomtibb.de/wiki/index.php?action=history&amp;feed=atom&amp;title=HomeAssistant_Programmierung_%28dunder%29_future_%28dunder%29"/>
	<link rel="alternate" type="text/html" href="https://tippvomtibb.de/wiki/index.php?title=HomeAssistant_Programmierung_(dunder)_future_(dunder)&amp;action=history"/>
	<updated>2026-07-16T11:14:34Z</updated>
	<subtitle>Versionsgeschichte dieser Seite in TippvomTibb</subtitle>
	<generator>MediaWiki 1.44.0</generator>
	<entry>
		<id>https://tippvomtibb.de/wiki/index.php?title=HomeAssistant_Programmierung_(dunder)_future_(dunder)&amp;diff=4985&amp;oldid=prev</id>
		<title>Chris T. Ludwig: Die Seite wurde neu angelegt: „&lt;code&gt;__future__&lt;/code&gt; ist kein Bestandteil von Home Assistant selbst, sondern ein spezielles Python-Modul. Es ermoeglicht, Sprachfunktionen einer neueren Python-Version bereits in aelteren Python-Versionen zu verwenden.  Beispiel:  &lt;syntaxhighlight lang=&quot;python&quot;&gt;from __future__ import annotations&lt;/syntaxhighlight&gt; Das wirst du in &#039;&#039;&#039;fast jeder modernen Home-Assistant-Integration&#039;&#039;&#039; ganz oben in der Datei finden.   -----  == Was bewirkt &lt;code&gt;annotations…“</title>
		<link rel="alternate" type="text/html" href="https://tippvomtibb.de/wiki/index.php?title=HomeAssistant_Programmierung_(dunder)_future_(dunder)&amp;diff=4985&amp;oldid=prev"/>
		<updated>2026-07-05T05:36:33Z</updated>

		<summary type="html">&lt;p&gt;Die Seite wurde neu angelegt: „&amp;lt;code&amp;gt;__future__&amp;lt;/code&amp;gt; ist kein Bestandteil von Home Assistant selbst, sondern ein spezielles Python-Modul. Es ermoeglicht, Sprachfunktionen einer neueren Python-Version bereits in aelteren Python-Versionen zu verwenden.  Beispiel:  &amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;from __future__ import annotations&amp;lt;/syntaxhighlight&amp;gt; Das wirst du in &amp;#039;&amp;#039;&amp;#039;fast jeder modernen Home-Assistant-Integration&amp;#039;&amp;#039;&amp;#039; ganz oben in der Datei finden.   -----  == Was bewirkt &amp;lt;code&amp;gt;annotations…“&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Neue Seite&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;lt;code&amp;gt;__future__&amp;lt;/code&amp;gt; ist kein Bestandteil von Home Assistant selbst, sondern ein spezielles Python-Modul. Es ermoeglicht, Sprachfunktionen einer neueren Python-Version bereits in aelteren Python-Versionen zu verwenden.&lt;br /&gt;
&lt;br /&gt;
Beispiel:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;from __future__ import annotations&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Das wirst du in &amp;#039;&amp;#039;&amp;#039;fast jeder modernen Home-Assistant-Integration&amp;#039;&amp;#039;&amp;#039; ganz oben in der Datei finden.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
-----&lt;br /&gt;
&lt;br /&gt;
== Was bewirkt &amp;lt;code&amp;gt;annotations&amp;lt;/code&amp;gt;? ==&lt;br /&gt;
&lt;br /&gt;
Nehmen wir dieses Beispiel:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;class FoxAPI:&lt;br /&gt;
    pass&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class Coordinator:&lt;br /&gt;
&lt;br /&gt;
    def __init__(self, api: FoxAPI):&lt;br /&gt;
        self.api = api&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Ohne&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;from __future__ import annotations&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
muss Python beim Einlesen der Datei bereits wissen, was &amp;lt;code&amp;gt;FoxAPI&amp;lt;/code&amp;gt; ist.&lt;br /&gt;
&lt;br /&gt;
Mit&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;from __future__ import annotations&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
werden alle Typangaben zunächst nur als &amp;#039;&amp;#039;&amp;#039;Zeichenketten&amp;#039;&amp;#039;&amp;#039; gespeichert und erst später ausgewertet.&lt;br /&gt;
&lt;br /&gt;
Dadurch funktionieren auch sogenannte &amp;#039;&amp;#039;&amp;#039;Forward References&amp;#039;&amp;#039;&amp;#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;from __future__ import annotations&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class A:&lt;br /&gt;
&lt;br /&gt;
    def test(self) -&amp;gt; B:&lt;br /&gt;
        ...&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Obwohl &amp;lt;code&amp;gt;B&amp;lt;/code&amp;gt; erst später definiert wird:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;class B:&lt;br /&gt;
    pass&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Ohne &amp;lt;code&amp;gt;__future__&amp;lt;/code&amp;gt; würde das einen Fehler erzeugen.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
-----&lt;br /&gt;
&lt;br /&gt;
== Warum nutzt Home Assistant das? ==&lt;br /&gt;
&lt;br /&gt;
Home Assistant verwendet sehr viele Typannotationen:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;from homeassistant.core import HomeAssistant&lt;br /&gt;
from homeassistant.config_entries import ConfigEntry&lt;br /&gt;
&lt;br /&gt;
async def async_setup_entry(&lt;br /&gt;
    hass: HomeAssistant,&lt;br /&gt;
    entry: ConfigEntry,&lt;br /&gt;
) -&amp;gt; bool:&lt;br /&gt;
    ...&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Ebenso häufig findet man:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;class FoxCoordinator(DataUpdateCoordinator[dict[str, Any]]):&lt;br /&gt;
    ...&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
oder&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;def __init__(&lt;br /&gt;
    self,&lt;br /&gt;
    coordinator: FoxCoordinator,&lt;br /&gt;
) -&amp;gt; None:&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Mit&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;from __future__ import annotations&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* werden Importabhängigkeiten reduziert,&lt;br /&gt;
* entstehen weniger zyklische Importe,&lt;br /&gt;
* verbessert sich die Performance beim Laden,&lt;br /&gt;
* und der Code wird einfacher wartbar.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
-----&lt;br /&gt;
&lt;br /&gt;
== Warum steht der Import immer ganz oben? ==&lt;br /&gt;
&lt;br /&gt;
Python verlangt, dass alle &amp;lt;code&amp;gt;__future__&amp;lt;/code&amp;gt;-Importe vor allen anderen Imports stehen:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;from __future__ import annotations&lt;br /&gt;
&lt;br /&gt;
import logging&lt;br /&gt;
&lt;br /&gt;
from homeassistant.core import HomeAssistant&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Das ist Pflicht.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
-----&lt;br /&gt;
&lt;br /&gt;
== Brauche ich das für eine neue Integration? ==&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Ja.&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Wenn du heute eine neue Home-Assistant-Integration schreibst, solltest du grundsätzlich jede Python-Datei mit&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;from __future__ import annotations&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
beginnen.&lt;br /&gt;
&lt;br /&gt;
Das entspricht dem Stil des Home-Assistant-Core-Projekts und erleichtert den Einsatz moderner Typannotationen.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
-----&lt;br /&gt;
== Wird das in Zukunft noch benoetigt? ==&lt;br /&gt;
&lt;br /&gt;
Home Assistant setzt inzwischen auf aktuelle Python-Versionen. Seit Python 3.14 werden verzoegert ausgewertete Annotationen standardmaeszig unterstuetzt, sodass &amp;lt;code&amp;gt;from __future__ import annotations&amp;lt;/code&amp;gt; langfristig ueberfluessig werden wird.&lt;br /&gt;
&lt;br /&gt;
Bis dahin gilt jedoch:&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Für Home-Assistant-Integrationen:&amp;#039;&amp;#039;&amp;#039; weiter verwenden.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Für neuen Home-Assistant-Code:&amp;#039;&amp;#039;&amp;#039; praktisch Standard.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Für aeltere Tutorials:&amp;#039;&amp;#039;&amp;#039; Wenn der Import fehlt, ist der Code oft älter oder richtet sich an fruehere Python-Versionen.&lt;br /&gt;
&lt;br /&gt;
Man solltedie Codezeile unbedingt in jeder eigenen Home-Assistant-Geraeteintegrationen konsequent &amp;lt;code&amp;gt;.py&amp;lt;/code&amp;gt;-Datei verwenden.&lt;/div&gt;</summary>
		<author><name>Chris T. Ludwig</name></author>
	</entry>
</feed>