Skip to content

Misc type hint fixes#278

Closed
stephenfin wants to merge 8 commits intosqlalchemy:mainfrom
stephenfin:typing
Closed

Misc type hint fixes#278
stephenfin wants to merge 8 commits intosqlalchemy:mainfrom
stephenfin:typing

Conversation

@stephenfin
Copy link
Copy Markdown
Contributor

A collection of typing-related changes built while typing oslo.cache.

Copy link
Copy Markdown
Member

@zzzeek zzzeek left a comment

Choose a reason for hiding this comment

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

oh. wow OK, I had forgotten that we hadn't turned on strict typing for dogpile.

can you do me a favor and let's turn on a little bit of strict - if i do this on the current main, it produces only 19 errors which are likely mostly handled here:

diff --git a/pyproject.toml b/pyproject.toml
index f8a77a2..7e0e293 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -58,6 +58,17 @@ valkey = [
 [project.entry-points."mako.cache"]
 "dogpile.cache" = "dogpile.cache.plugins.mako_cache:MakoPlugin"
 
+[tool.mypy]
+show_error_codes = true
+incremental = true
+
+strict = true
+
+disallow_untyped_defs = false
+disallow_untyped_calls = false
+ignore_missing_imports = true
+
+
 [tool.setuptools]
 zip-safe = false
 include-package-data = true

This requires we remove the old mypy.ini file.

The collections.abc changes here are surprising to me and I dont see mypy errors locally for those, can you provide background on those? I dont see what's wrong with the typing version of those collections.

@stephenfin
Copy link
Copy Markdown
Contributor Author

oh. wow OK, I had forgotten that we hadn't turned on strict typing for dogpile.

can you do me a favor and let's turn on a little bit of strict - if i do this on the current main, it produces only 19 errors which are likely mostly handled here:

diff --git a/pyproject.toml b/pyproject.toml
index f8a77a2..7e0e293 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -58,6 +58,17 @@ valkey = [
 [project.entry-points."mako.cache"]
 "dogpile.cache" = "dogpile.cache.plugins.mako_cache:MakoPlugin"
 
+[tool.mypy]
+show_error_codes = true
+incremental = true
+
+strict = true
+
+disallow_untyped_defs = false
+disallow_untyped_calls = false
+ignore_missing_imports = true
+
+
 [tool.setuptools]
 zip-safe = false
 include-package-data = true

This requires we remove the old mypy.ini file.

Will do 👌

The collections.abc changes here are surprising to me and I dont see mypy errors locally for those, can you provide background on those? I dont see what's wrong with the typing version of those collections.

They're one of those things (like List and Tuple) that are deprecated since the stdlib has caught up and made them subscriptable. I've called it out in the commit message.

@zzzeek
Copy link
Copy Markdown
Member

zzzeek commented Oct 1, 2025

The collections.abc changes here are surprising to me and I dont see mypy errors locally for those, can you provide background on those? I dont see what's wrong with the typing version of those collections.

They're one of those things (like List and Tuple) that are deprecated since the stdlib has caught up and made them subscriptable. I've called it out in the commit message.

FTR that link is https://docs.python.org/3/library/typing.html#aliases-to-container-abcs-in-collections-abc

wow that's going to mess with me

@zzzeek zzzeek requested a review from sqla-tester October 1, 2025 14:00
Copy link
Copy Markdown
Collaborator

@sqla-tester sqla-tester left a comment

Choose a reason for hiding this comment

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

OK, this is sqla-tester setting up my work on behalf of zzzeek to try to get revision c798805 of this pull request into gerrit so we can run tests and reviews and stuff

@sqla-tester
Copy link
Copy Markdown
Collaborator

New Gerrit review created for change c798805: https://gerrit.sqlalchemy.org/c/sqlalchemy/dogpile.cache/+/6182

@stephenfin
Copy link
Copy Markdown
Contributor Author

CI failures were because I used the new union syntax instead of typing.Union. Will fix.

All of these things are unnecessary in Python 3.9 [1].

[1] https://docs.python.org/3/library/typing.html#aliases-to-container-abcs-in-collections-abc

Signed-off-by: Stephen Finucane <stephen@that.guru>
Copy link
Copy Markdown
Collaborator

@sqla-tester sqla-tester left a comment

Choose a reason for hiding this comment

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

OK, this is sqla-tester setting up my work on behalf of zzzeek to try to get revision 163b4e9 of this pull request into gerrit so we can run tests and reviews and stuff

@sqla-tester
Copy link
Copy Markdown
Collaborator

Patchset 163b4e9 added to existing Gerrit review https://gerrit.sqlalchemy.org/c/sqlalchemy/dogpile.cache/+/6182

Signed-off-by: Stephen Finucane <stephen@that.guru>
Signed-off-by: Stephen Finucane <stephen@that.guru>
This keeps both mypy and flake8 happy. Win win.

Signed-off-by: Stephen Finucane <stephen@that.guru>
Signed-off-by: Stephen Finucane <stephen@that.guru>
We move the configuration to pyproject.toml and enable strict mode
(though we disable some settings since we're not fully typed yet).

While here we also remove a redundant setting for black: black (and
ruff) will automatically infer the target version from
'[project.requires-python]'

Signed-off-by: Stephen Finucane <stephen@that.guru>
Copy link
Copy Markdown
Collaborator

@sqla-tester sqla-tester left a comment

Choose a reason for hiding this comment

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

OK, this is sqla-tester setting up my work on behalf of zzzeek to try to get revision aa04d4d of this pull request into gerrit so we can run tests and reviews and stuff

@sqla-tester
Copy link
Copy Markdown
Collaborator

Patchset aa04d4d added to existing Gerrit review https://gerrit.sqlalchemy.org/c/sqlalchemy/dogpile.cache/+/6182

@zzzeek
Copy link
Copy Markdown
Member

zzzeek commented Oct 1, 2025

i've got some other things moving in dogpile.cache where you'd need a rebase on this, but if this is ready I can just finalize in gerrit and merge

@stephenfin
Copy link
Copy Markdown
Contributor Author

stephenfin commented Oct 1, 2025 via email

@zzzeek
Copy link
Copy Markdown
Member

zzzeek commented Oct 1, 2025

ok great.

@sqla-tester
Copy link
Copy Markdown
Collaborator

Michael Bayer (zzzeek) wrote:

recheck

View this in Gerrit at https://gerrit.sqlalchemy.org/c/sqlalchemy/dogpile.cache/+/6182

@stephenfin
Copy link
Copy Markdown
Contributor Author

@zzzeek I'm not sure if that error is related to this change? It doesn't appear to be, especially given I'm not making any functional changes. Another recheck needed?

A Sequence requires the ability to index (__getitem__) and retrieve the
length (__len__), amongst other options. An Iterable simply required the
ability to iterate (__iter__). This allows us to pass, amongst other
things, dict_keys, to the 'get_multi', 'get_serialized_multi', and
'delete_multi' methods, which seems like a rational thing to want and be
able to do.

Signed-off-by: Stephen Finucane <stephen@that.guru>
@stephenfin
Copy link
Copy Markdown
Contributor Author

I think this is ready. There's more that'll likely pop up since we're not fully typed but I won't be back on this for another week or two.

I tell a lie: another thing popped up yesterday. I've just pushed it (I want to be able to pass the value of dict.keys() to get_multi, since we do that in a few places in oslo.cache).

This is helpful if the expiration_time callable relies on some global
configuration, for example.

Signed-off-by: Stephen Finucane <stephen@that.guru>
@zzzeek
Copy link
Copy Markdown
Member

zzzeek commented Oct 2, 2025

do you have access to push to the gerrit? since you're gerrit enabled. I already put a little changelog into it. the failures are because I'm messing with the CI and added a tox target, so I just rebased the gerrit to hopefully get those.

Comment thread dogpile/cache/region.py
]

ExpirationTimeCallable = Callable[[], float]
ExpirationTimeCallable = Callable[[], Optional[float]]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

yup looks like the way it's used already expects None

Comment thread dogpile/cache/api.py
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

sure. these are all collections of keys that we only iterate. wonder why I put Sequence there.

Comment thread mypy.ini
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

Comment thread dogpile/cache/api.py
pickle.dumps
)
deserializer: Union[None, Deserializer] = staticmethod( # type: ignore
) # type: ignore
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

let me turn on warn_unused_ignores for these

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

wow, no errors, OK.

@sqla-tester
Copy link
Copy Markdown
Collaborator

Gerrit review https://gerrit.sqlalchemy.org/c/sqlalchemy/dogpile.cache/+/6182 has been merged. Congratulations! :)

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.

3 participants