-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Make PyCollector an implementation detail - don't use in hook type annotation #9264
Conversation
I thought it was intended to be able to subclass some of them (say, @RonnyPfannschmidt do you have something to add to that? |
Initially those classes where exposed and subclassable/over rideable, |
Subclassing is not a problem, since a subclass of e.g. A break can occur if a collector which subclasses |
Thanks, just commented on that for clarification, as I misunderstood your description as |
8a4aa2d
to
96066f6
Compare
I rebased to remove |
The So this should be good to go if we want to go with hiding |
What's the state here? Should this go into 7.0? |
Waiting for review.
Not really, can go after. |
@@ -360,7 +360,7 @@ def pytest_pycollect_makemodule( | |||
|
|||
@hookspec(firstresult=True) | |||
def pytest_pycollect_makeitem( | |||
collector: "PyCollector", name: str, obj: object | |||
collector: Union["Module", "Class"], name: str, obj: object | |||
) -> Union[None, "Item", "Collector", List[Union["Item", "Collector"]]]: | |||
"""Return a custom item/collector for a Python object in a module, or None. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"""Return a custom item/collector for a Python object in a module, or None. | |
"""Return a custom item/collector for a Python object in a module or class, or None. |
…notation The `pytest_pycollector_makeitem` argument `collector` is currently annotated with type `PyCollector`. As part of pytest-dev#7469, that would have required us to expose it in the public API. But really it's an implementation detail, not something we want to expose. So replace the annotation with the concrete python collector types that are passed. Strictly speaking, `pytest_pycollector_makeitem` is called from `PyCollector.collect()`, so the new type annotation is incorrect if another type subclasses `PyCollector`. But the set of python collectors is closed (mapping to language constructs), and the type is private, so there shouldn't be any other deriving classes, and we can consider it effectively sealed (unfortunately Python does not provide a way to express this - yet?).
96066f6
to
e05e696
Compare
The
pytest_pycollector_makeitem
argumentcollector
is currently annotated with typePyCollector
. As part of #7469, that would have required us to expose it in the public API. But really it's an implementation detail, not something we want to expose. So replace the annotation with the concrete python collector types that are passed.Strictly speaking,
pytest_pycollect_makeitem
is called fromPyCollector.collect()
, so the new type annotation is incorrect if another type subclassesPyCollector
. But the set of python collectors is closed (mapping to language constructs), and the type is private, so there shouldn't be any other deriving classes, and we can consider it effectively sealed (unfortunately Python does not provide a way to express this - yet?).