Repository navigation
Conversation
Owner
|
Errors in workflow checks are not your problem, I haven't touched the codebase for a long while, and various type checkers have progressed significantly during all this time. I will try to spend some time these days. |
andersk
force-pushed
the
xpath-function-context
branch
from
September 25, 2026 10:02
dc70b3a to
a386551
Compare
Every XPath extension function receives a context object as its first argument, which provides the context_node and eval_context properties (https://lxml.de/extensions.html#the-xpath-context). Add a stub-only _BaseContext class describing it, and require functions registered in _XPathFunctionNamespaceRegistry to accept it as first argument. At runtime the context is an _XPathContext or an _XSLTContext, since the same function namespace registry serves both XPath and XSLT, so the common base class is used. The decorator form now uses a TypeVar bound to the extension function type instead of a ParamSpec, so the decorated function's type is preserved exactly, including the annotation of its first parameter. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Apply the same context-first-argument requirement introduced for
FunctionNamespace to the extensions= argument of _Element.xpath(),
_ElementTree.xpath(), XPath, ETXPath, XPathElementEvaluator,
XPathDocumentEvaluator and XPathEvaluator, and to the return type of
Extension().
Because dict values are invariant, a plain
dict[..., Callable[Concatenate[_BaseContext, ...], Any]] parameter
would make mypy reject correct code such as an inferred
{("ns", "f"): f} dict variable. The dict forms therefore use a TypeVar
bound to the extension function type, so the value type is solved
instead of compared invariantly.
Compatibility: extension functions that take no arguments, or whose
first parameter is annotated with a type incompatible with
_BaseContext, are now rejected. Unannotated functions, and dicts
explicitly annotated with Callable[..., Any] values, are accepted as
before.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
andersk
force-pushed
the
xpath-function-context
branch
from
September 25, 2026 23:46
a386551 to
4fe4a3e
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Every XPath extension function receives a context object as its first argument, which provides the
context_nodeandeval_contextproperties. Add a stub-only_BaseContextclass describing it, and require functions registered in_XPathFunctionNamespaceRegistryto accept it as first argument.At runtime the context is an
_XPathContextor an_XSLTContext, since the same function namespace registry serves both XPath and XSLT, so the common base class is used.