From 85e8b72f40143423ece6ed575b39750d13259fc1 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner <inform@tiker.net> Date: Mon, 18 Apr 2022 00:37:06 -0500 Subject: [PATCH] Fix type annotation of Taggable.tags_of_type --- doc/conf.py | 1 - pytools/tag.py | 14 ++++++-------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/doc/conf.py b/doc/conf.py index 068615d..70a55f0 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -31,7 +31,6 @@ intersphinx_mapping = { "https://documen.tician.de/loopy/": None, } - nitpick_ignore_regex = [ ["py:class", r"typing_extensions\.(.+)"], ] diff --git a/pytools/tag.py b/pytools/tag.py index 032a850..ce05f48 100644 --- a/pytools/tag.py +++ b/pytools/tag.py @@ -18,9 +18,9 @@ Supporting Functionality Internal stuff that is only here because the documentation tool wants it ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -.. class:: TagsOfTypeT +.. class:: TagT - A type variable used in :meth:`Taggable.tags_of_type`. + A type variable with lower bound :class:`Tag`. """ import sys @@ -166,7 +166,7 @@ class UniqueTag(Tag): ToTagSetConvertible = Union[Iterable[Tag], Tag, None] -TagsOfTypeT = TypeVar("TagsOfTypeT", bound="Type[Tag]") +TagT = TypeVar("TagT", bound="Tag") # {{{ UniqueTag rules checking @@ -313,15 +313,13 @@ class Taggable: return self._with_new_tags(tags=check_tag_uniqueness(new_tags)) @memoize_method - def tags_of_type(self, tag_t: TagsOfTypeT) -> FrozenSet[TagsOfTypeT]: + def tags_of_type(self, tag_t: Type[TagT]) -> FrozenSet[TagT]: """ Returns *self*'s tags of type *tag_t*. """ - # type-ignore reason: mypy can't tell the generator has elements of - # type 'TagsOfTypeT' (infers it as elements of type 'Tag') - return frozenset(tag # type: ignore[misc] + return frozenset({tag for tag in self.tags - if isinstance(tag, tag_t)) + if isinstance(tag, tag_t)}) # }}} -- GitLab