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

implement Ruff #9

Merged
merged 15 commits into from
Feb 15, 2024
Merged

implement Ruff #9

merged 15 commits into from
Feb 15, 2024

Conversation

bandophahita
Copy link
Contributor

No description provided.

perrygoy
perrygoy previously approved these changes Feb 13, 2024
Copy link
Member

@perrygoy perrygoy left a comment

Choose a reason for hiding this comment

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

Thank you for all this polish, @bandophahita!

I had a few very minor suggestions that are not blocking.

pyproject.toml Outdated Show resolved Hide resolved
from screenpy.exceptions import UnableToAnswer
from screenpy.pacing import beat

from ..abilities import MakeAPIRequests

if TYPE_CHECKING:
from screenpy import Actor

subscripts = Union[str, int, slice]
Copy link
Member

Choose a reason for hiding this comment

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

We can move this (and the from typing import Union) into the if TYPE_CHECKING block.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved the alias. I let ruff automatically handle the imports.
I noticed it doesn't bother moving the union down into the TYPE_CHECKING block when other items are being imported from the module. My guess is it doesn't save anything.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, the main point of moving project code for type hinting into the if TYPE_CHECKING block is to reduce the chance of circular imports caused by type hints, and importing from typing will never cause that.

But i kinda like just moving all the type hinting stuff into that block, since we're using it anyway. I dunno, personal preference.

from typing import MutableMapping
from __future__ import annotations

from typing import TYPE_CHECKING, MutableMapping
Copy link
Member

Choose a reason for hiding this comment

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

We can move the MutableMapping into the if TYPE_CHECKING block.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same deal here as the Union. I'm guessing ruff sees this as a no-op move so it opts to leave it alone.

Comment on lines 87 to 101
test_method = "TEST"
test_method: str = "TESTYTEST"
Copy link
Member

Choose a reason for hiding this comment

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

Was this change really necessary? Weird.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I opted to use an uncommon (guaranteed not to be present in the docstring) value; lowering the chance of a false positive.

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, i should have been more specific—was adding : str necessary? I was OK with the string change, it's funny.

Copy link
Contributor Author

@bandophahita bandophahita Feb 14, 2024

Choose a reason for hiding this comment

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

Oops. I didn't need to leave the annotation in.
I was trying to fix a problem with mypy not liking assert test_method in SendTESTMethod.__doc__ because __doc__ can be str | None and str in None is invalid.

Once I added the assertion assert SendTESTMethod.__doc__ is not None mypy calmed down. I just forgot to take the annotation off.

@bandophahita
Copy link
Contributor Author

I updated the ruff config to push as many imports into TYPE_CHECKING as it can.

@bandophahita bandophahita self-assigned this Feb 15, 2024
Copy link
Member

@perrygoy perrygoy left a comment

Choose a reason for hiding this comment

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

A few comments of support, looks good! Thanks for getting this in @bandophahita!

Comment on lines -66 to +67
self.headers = dict(header_pairs[0]) # type: ignore
self.headers = dict(cast(Iterable, header_pairs[0]))
Copy link
Member

Choose a reason for hiding this comment

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

Trust us mypy we know what we're talkin' about here.

Comment on lines -79 to +85
return response
except JSONDecodeError:
response = responses[-1].text
for part in self.body_parts:
response = response[part]
return response
return response
Copy link
Member

Choose a reason for hiding this comment

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

Man, i really should have noticed this one. Hahaha. Thanks, linting!

Copy link
Member

Choose a reason for hiding this comment

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

I removed setup.py from screenpy_playwright and everything worked... maybe it's time to delete this one in the "Project standardization" PR?

@bandophahita bandophahita merged commit 155f036 into ScreenPyHQ:trunk Feb 15, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants