Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mypy app-wide scope #786

Merged
merged 7 commits into from
Sep 5, 2023
Merged

Mypy app-wide scope #786

merged 7 commits into from
Sep 5, 2023

Conversation

why-not-try-calmer
Copy link
Contributor

@why-not-try-calmer why-not-try-calmer commented Aug 31, 2023

This extends the scope of the static type-checker to also encompass docker-app and docker-redis.

@why-not-try-calmer why-not-try-calmer added the chore Maintanance, clean-up and other not fancy improvements. label Aug 31, 2023
@why-not-try-calmer why-not-try-calmer changed the title Mypy app wide scope Mypy app-wide scope Aug 31, 2023
@why-not-try-calmer why-not-try-calmer requested review from suricactus and faebebin and removed request for suricactus September 1, 2023 11:24
Copy link
Member

@faebebin faebebin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

a couple of small proposals

if isinstance(some_user, User):
users.append(some_user)
else:
users += some_user
assert len(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could it be:

users: list[User] = [some_user] if isintance(some_user, User) else some_users

BTW i would rather keep the var name users because it is simpler?

Copy link
Contributor Author

@why-not-try-calmer why-not-try-calmer Sep 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that works too, that's actually a good use of variable shadowing

@why-not-try-calmer
Copy link
Contributor Author

LGTM

a couple of small proposals

Thanks, ready for me

@why-not-try-calmer why-not-try-calmer merged commit 6354b2d into master Sep 5, 2023
@why-not-try-calmer why-not-try-calmer deleted the mypy-app-wide-scope branch September 5, 2023 06:10
Copy link
Collaborator

@suricactus suricactus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, @why-not-try-calmer @faebebin . Thanks for the contribution and reviews.

There are a couple of problems that from this PR, the worst of them in docker-app/qfieldcloud/subscription/models.py line 815 -> the assert there is changing the behaviour of the app, therefore breaking it.

I caught this error when trying to integrate this PR changes with web UI.

I would suggest for such quite fundamental changes we have a double review, cool down period and opening a PR on the web ui to verify the changes are working.

See #791 for the fixes.

'Organization "{}" cannot be added. Only users and teams can be collaborators.'
).format(username),
message = _(
f'Organization "{username}" cannot be added. Only users and teams can be collaborators.'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@faebebin @why-not-try-calmer

I have already commented this in another place, this replacing "{}".format(1) with f"{1}" is causing troubles for potential translations.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@@ -794,7 +794,7 @@ def create_subscription(
plan: Plan,
created_by: Person,
active_since: Optional[datetime] = None,
) -> Tuple["Subscription", "Subscription"]:
) -> tuple[Optional["AbstractSubscription"], "AbstractSubscription"]:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't you use the definition from the docs: tuple[AbstractSubscription | None, AbstractSubscription] ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@@ -794,7 +794,7 @@ def create_subscription(
plan: Plan,
created_by: Person,
active_since: Optional[datetime] = None,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one should be datetime | None as all other places, no?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Comment on lines +815 to +816
assert active_since

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@why-not-try-calmer @faebebin

This assert is actually breaking the system, as we have situations where we DO allow no active since to be passed. You can clearly see that from the typing of the function argument.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for fixing 👍

@why-not-try-calmer
Copy link
Contributor Author

why-not-try-calmer commented Sep 8, 2023

Hey, @why-not-try-calmer @faebebin . Thanks for the contribution and reviews.

There are a couple of problems that from this PR, the worst of them in docker-app/qfieldcloud/subscription/models.py line 815 -> the assert there is changing the behaviour of the app, therefore breaking it.

I caught this error when trying to integrate this PR changes with web UI.

I would suggest for such quite fundamental changes we have a double review, cool down period and opening a PR on the web ui to verify the changes are working.

See #791 for the fixes.

I merged this quite early after only 1 approval so it's on me. I think it makes sense indeed to let you / the project owner do the merges for anything non-trivial, especially when several pending PRs can impact each other.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore Maintanance, clean-up and other not fancy improvements.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants