Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
f6745ce to
a3cb55c
Compare
msullivan
approved these changes
Feb 11, 2026
typemap/type_eval/_apply_generic.py
Outdated
| functions: tuple[types.FunctionType, ...] | ||
|
|
||
|
|
||
| def _is_overloaded_function(func): |
Collaborator
There was a problem hiding this comment.
Seems a bad name, because it's getting the overloaded function.
typemap/type_eval/_apply_generic.py
Outdated
|
|
||
|
|
||
| def _is_overloaded_function(func): | ||
| module_overload_registry = typing._overload_registry[func.__module__] |
Collaborator
There was a problem hiding this comment.
Can we not use typing.get_overloads? If there's some reason we can't, document it here.
Comment on lines
-408
to
-487
| # TODO: Potentially most of this could be ripped out. The internals | ||
| # don't use this at all, it's only used by format_class. | ||
| def _flatten_class_explicit( | ||
| cls: type[Any], ctx: _eval_typing.EvalContext | ||
| ) -> type[_eval_typing._EvalProxy]: | ||
| cls_boxed = box(cls) | ||
| mro_boxed = cls_boxed.mro | ||
|
|
||
| # TODO: I think we want to create the whole mro chain... | ||
| # before we evaluate the contents? | ||
|
|
||
| # FIXME: right now we flatten out all the attributes... but should we?? | ||
| # XXX: Yeah, a lot of work is put into copying everything into every | ||
| # class and it is not worth it, at all. | ||
|
|
||
| new = {} | ||
|
|
||
| # Run through the mro and populate everything | ||
| for boxed in reversed(mro_boxed): | ||
| # We create it early so we can add it to seen, to handle recursion | ||
| # XXX: currently we are doing this even for types with no generics... | ||
| # that simplifies the flow... - probably keep it this way until | ||
| # we stop flattening attributes into every class | ||
| name = boxed.cls.__name__ | ||
| cboxed: Any | ||
|
|
||
| args = tuple(boxed.args.values()) | ||
| args_str = ", ".join(_type_repr(a) for a in args) | ||
| fullname = f"{name}[{args_str}]" if args_str else name | ||
| cboxed = type( | ||
| fullname, | ||
| (_eval_typing._EvalProxy,), | ||
| { | ||
| "__module__": boxed.cls.__module__, | ||
| "__name__": fullname, | ||
| "__origin__": boxed.cls, | ||
| "__local_args__": args, | ||
| }, | ||
| ) | ||
| new[boxed] = cboxed | ||
|
|
||
| annos: dict[str, Any] = {} | ||
| dct: dict[str, Any] = {} | ||
| sources: dict[str, Any] = {} | ||
|
|
||
| cboxed.__local_annotations__, cboxed.__local_defns__ = get_local_defns( | ||
| boxed | ||
| ) | ||
| for base in reversed(boxed.mro): | ||
| cbase = new[base] | ||
| annos.update(cbase.__local_annotations__) | ||
| dct.update(cbase.__local_defns__) # uh. | ||
| for k in [*cbase.__local_annotations__, *cbase.__local_defns__]: | ||
| sources[k] = cbase | ||
|
|
||
| cboxed.__defn_names__ = set(dct) | ||
| cboxed.__annotations__ = annos | ||
| cboxed.__defn_sources__ = sources | ||
| cboxed.__generalized_mro__ = [new[b] for b in boxed.mro] | ||
|
|
||
| for k, v in dct.items(): | ||
| setattr(cboxed, k, v) | ||
|
|
||
| # Run through the mro again and evaluate everything | ||
| for cboxed in new.values(): | ||
| for k, v in cboxed.__annotations__.items(): | ||
| cboxed.__annotations__[k] = _eval_typing._eval_types(v, ctx=ctx) | ||
|
|
||
| for k in cboxed.__defn_names__: | ||
| v = cboxed.__dict__[k] | ||
| setattr(cboxed, k, _eval_typing._eval_types(v, ctx=ctx)) | ||
|
|
||
| return new[cls_boxed] | ||
|
|
||
|
|
||
| def flatten_class_explicit(obj: typing.Any): | ||
| with _eval_typing._ensure_context() as ctx: | ||
| return _flatten_class_explicit(obj, ctx) | ||
|
|
||
|
|
Collaborator
There was a problem hiding this comment.
Remove this dead code as a standalone PR, please, since it might be worth recovering at some point.
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.
No description provided.