Is name=None correct for NodeImage constructor?
- Vorherrschende Sprache
- Python
- Sterne
- 2.1k
- Forks
- 931
- Ø Merge
- 1 T. 2 Std.
- Gemergte PRs (30 T.)
- 4
Beschreibung
## Summary
If someone copy-pastes code from [this example](https://github.com/apache/libcloud/blob/v3.8.0/docs/examples/compute/create_ec2_node_custom_ami.py#L22), they will get type errors in a type checker like [pyright](https://github.com/microsoft/pyright).
## Detailed Information
The type hints for NodeImage say that `name` is a `str`:
https://github.com/apache/libcloud/blob/v3.8.0/libcloud/compute/base.py#L451
However, in one of the examples in docs, `name` is set to `None`:
https://github.com/apache/libcloud/blob/v3.8.0/docs/examples/compute/create_ec2_node_custom_ami.py#L22
https://libcloud.readthedocs.io/en/stable/compute/examples.html#create-ec2-node-using-a-custom-ami
This means that a type-checker like pyright will complain if you follow this example.
Should the type hint and/or the example be changed?
My workaround was to add `# type: ignore` to silence the warning, but I figured I can open an issue in case someone else might run into the same thing.
Beitragsleitfaden
Rechercherichtung
Beginne mit NodeImage in libcloud/compute/base.py und vergleiche dessen Namensannotation mit dem Wert None in docs/examples/compute/create_ec2_node_custom_ami.py. Prüfe das Beispiel mit pyright und entscheide anschließend, ob die Annotation oder das Beispiel der vorgesehenen API entspricht. Als erledigt gilt die Aufgabe, wenn Beispiel und Type Hints übereinstimmen, ohne einen type-ignore-Workaround zu erfordern.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- api, cloud
- Issue-Typ
- Bug
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 48/100