You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The BigQueryReservation class has mutable instances attributes that are being assigned to at various stages of the control flow. This makes it hard to understand for the reader and the type checker when they are expected to already be initialized and when not. I had to add several redundant assertions to help the type checker along. See FIXME. To see the type checker's confusion first hand, revert the commit that adds the FIXME (except for the hunk that adds the module to .mypy.ini) and run mypy:
src/azul/bigquery_reservation.py:131: error: Item "None" of "Reservation | None" has no attribute "autoscale" [union-attr]
src/azul/bigquery_reservation.py:133: error: Item "None" of "Reservation | None" has no attribute "autoscale" [union-attr]
src/azul/bigquery_reservation.py:172: error: Item "None" of "Reservation | None" has no attribute "autoscale" [union-attr]
src/azul/bigquery_reservation.py:192: error: Item "None" of "Reservation | None" has no attribute "name" [union-attr]
src/azul/bigquery_reservation.py:193: error: Item "None" of "Reservation | None" has no attribute "name" [union-attr]
src/azul/bigquery_reservation.py:223: error: Name "Union" is not defined [name-defined]
src/azul/bigquery_reservation.py:223: note: Did you forget to import it from "typing"? (Suggestion: "from typing import Union")
src/azul/bigquery_reservation.py:229: error: Name "Union" is not defined [name-defined]
src/azul/bigquery_reservation.py:229: note: Did you forget to import it from "typing"? (Suggestion: "from typing import Union")
src/azul/bigquery_reservation.py:235: error: Variable "azul.bigquery_reservation.BigQueryReservation.ResourcePager" is not valid as a type [valid-type]
src/azul/bigquery_reservation.py:235: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
src/azul/bigquery_reservation.py:235: error: Name "Optional" is not defined [name-defined]
src/azul/bigquery_reservation.py:235: note: Did you forget to import it from "typing"? (Suggestion: "from typing import Optional")
src/azul/bigquery_reservation.py:236: error: Need type annotation for "resources" (hint: "resources': list[<type>] = ...") [var-annotated]
Found 10 errors in 1 file (checked 15 source files)
(.venv) hannes-m1bp:azul.hannes2.local hannes$
I think the control and information flow would be clearer if methods like create_reservation returned their result instead of assigning to a mutable instance attribute. The implicit post-condition is that self.reservation is not None when self.create_reservation returns. This post-condition can be made explicit by declaring def create_reservation(self, …) -> Reservation.
The text was updated successfully, but these errors were encountered:
The
BigQueryReservation
class has mutable instances attributes that are being assigned to at various stages of the control flow. This makes it hard to understand for the reader and the type checker when they are expected to already be initialized and when not. I had to add several redundant assertions to help the type checker along. See FIXME. To see the type checker's confusion first hand, revert the commit that adds the FIXME (except for the hunk that adds the module to.mypy.ini
) and runmypy
:I think the control and information flow would be clearer if methods like
create_reservation
returned their result instead of assigning to a mutable instance attribute. The implicit post-condition is thatself.reservation
is notNone
whenself.create_reservation
returns. This post-condition can be made explicit by declaringdef create_reservation(self, …) -> Reservation
.The text was updated successfully, but these errors were encountered: