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

Add type annotations #434

Merged
merged 9 commits into from
May 31, 2021
Merged

Conversation

mmaslowskicc
Copy link
Collaborator

@mmaslowskicc mmaslowskicc commented May 28, 2021

Fixes #432.

Type annotations, mypy configuration and needed fixes are added.

@codecov-commenter
Copy link

codecov-commenter commented May 28, 2021

Codecov Report

Merging #434 (3f846ad) into master (f343899) will decrease coverage by 0.31%.
The diff coverage is 57.95%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #434      +/-   ##
==========================================
- Coverage   68.37%   68.06%   -0.32%     
==========================================
  Files          23       23              
  Lines         623      645      +22     
==========================================
+ Hits          426      439      +13     
- Misses        197      206       +9     
Flag Coverage Δ
linux 67.59% <57.95%> (-0.14%) ⬇️
macos 65.42% <56.81%> (-0.39%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/pytest_postgresql/compat.py 5.55% <0.00%> (-0.70%) ⬇️
src/pytest_postgresql/factories/client.py 66.66% <ø> (ø)
src/pytest_postgresql/plugin.py 54.54% <0.00%> (ø)
src/pytest_postgresql/retry.py 61.11% <0.00%> (-9.48%) ⬇️
src/pytest_postgresql/port.py 21.87% <16.66%> (+0.44%) ⬆️
src/pytest_postgresql/executor.py 62.36% <21.42%> (+0.14%) ⬆️
src/pytest_postgresql/executor_noop.py 73.33% <25.00%> (-2.53%) ⬇️
src/pytest_postgresql/factories/noprocess.py 12.00% <50.00%> (ø)
src/pytest_postgresql/factories/process.py 60.46% <50.00%> (+0.94%) ⬆️
src/pytest_postgresql/janitor.py 67.56% <66.66%> (-0.44%) ⬇️
... and 9 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 097e16b...3f846ad. Read the comment docs.

Copy link
Member

@fizyk fizyk left a comment

Choose a reason for hiding this comment

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

Also add mypy jobs in .github/workflows/linters.yml

# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/psf/black
rev: 21.5b1
Copy link
Member

Choose a reason for hiding this comment

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

can this versions be taken from requirements file? Otherwise I might forget to update it manually and I'm not sure if dependabot will update it by itself 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I could change this to instead use only packages installed in the system, i.e. the ones from our virtualenv. That might be better here, while less consistent with usual usage of pre-commit.

Copy link
Member

Choose a reason for hiding this comment

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

connection = Any
if not TYPE_CHECKING:
# if there's no postgres, just go with the flow.
# pylint:disable=invalid-name
Copy link
Member

Choose a reason for hiding this comment

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

oh... we can rid of pylint comment here

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Are we intentionally not using pylint? Should I (separately) delete all such comments or fix it so pylint passes?

Copy link
Member

Choose a reason for hiding this comment

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

intentionally for now.
I left the formatting and most of the checks to black. As it often happened that one breaks the other and it takes a bit of tinkering with configuration for them to cooperate.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If it's ok, I'd prefer to delete the unused ignores in a separate PR.

Copy link
Member

Choose a reason for hiding this comment

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

nah, leave it be then

@@ -87,7 +90,7 @@ def __init__(
:param int port: port under which process is accessible
:param str datadir: path to postgresql datadir
:param str unixsocketdir: path to socket directory
:param pathlib.Path logfile: path to logfile for postgresql
:param str logfile: path to logfile for postgresql
Copy link
Member

Choose a reason for hiding this comment

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

just remove types from docstring

# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/psf/black
rev: 21.5b1
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I could change this to instead use only packages installed in the system, i.e. the ones from our virtualenv. That might be better here, while less consistent with usual usage of pre-commit.

"""Issue a stop request to executable."""
subprocess.check_output(
f"{self.executable} stop -D {self.datadir} -m f",
shell=True,
)
try:
super().stop(sig, exp_sig)
super().stop(sig, exp_sig) # type: ignore[arg-type]
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think this one results from mirakuru not using strict optional.

@@ -59,28 +60,33 @@ def get_port(ports):
if ports == -1:
return None
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Do we need that? I'm not sure if there is any situation where None returned from get_port is not a configuration error. In port_for.select_random lack of available ports causes an exception, so this function is not guaranteed to return None instead of raising an exception.

I think it would be simpler to always return an available port or raise an exception.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok, it's for pg_port = get_port(port) or get_port(config["port"]).

connection = Any
if not TYPE_CHECKING:
# if there's no postgres, just go with the flow.
# pylint:disable=invalid-name
Copy link
Member

Choose a reason for hiding this comment

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

intentionally for now.
I left the formatting and most of the checks to black. As it often happened that one breaks the other and it takes a bit of tinkering with configuration for them to cooperate.

@fizyk fizyk merged commit 4d66339 into ClearcodeHQ:master May 31, 2021
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.

Complete type annotations and PEP 561 compatibility
3 participants