Comments (4)
I agree, this should probably be easy!
from jedi.
Aside: I've since spotted that in Python 3.12, the type
statement results in the deprecation of TypeAlias
as an annotation. Not sure I really like that syntax either, but 🤷
from jedi.
Stepping through this the important bit is, I think, where we end up in tree_name_to_values
and fall through the annassign
branch within the loop for name in names
. This ends up computing the ValueSet
over the annotation, however in this case that's not really useful.
I'm not really sure what the idea change is though. We do need to run at least some of the infer...
logic on the annotation in order to know that it's typing.TypeAlias
(we could do some name hackery, but that doesn't feel like it's the right solution), however the results we get from infer_annotation(...).execute_annotation()
aren't really what we want. I think there might be a world where we do the infer_annotation(...)
part but not the execute_annotation()
part, however even that seems to go a bit too far -- we're into typing._SpecialForm
at that point, where I think we need an explicit marker that we're dealing with TypeAlias
.
I think one option here is to:
- Somehow intercept the processing of
TypeAlias
when we get into working out its symbol intyping
and perhaps return a custom type there - That type can then either be checked for in
tree_name_to_values
(by instance/property/whatever) such that we can know that we don't want to use the annotation and should look onwards at the assignment. ForTypeAlias
specifically we might even want to jump directly to processing the assigned value as a type, but I'm not sure that's entirely useful to add given that simply removing the: TypeAlias
part from the source seems to work fine even if the assigned value is a string.
The alternative I can think of here is perhaps more general, though potentially has other impacts. In theory I think we could opt to always evaluate the assigned value in the case where the type annotation doesn't resolve to anything useful. Exactly what "not useful" means here is debatable, but I'm mostly thinking of:
- stuff which isn't a type
- things which looks like types, but resolve to empty values (e.g: missing import)
- maybe some odd cases in
typing
(i.e: other_SpecialForm
s, which are likely to result in an emptyValueSet
after ``execute_annotation()`); this last one is the case I'm worried might have weird consequences here
These two things aren't exclusive either -- we could have both if we wanted.
I'm leaning more towards the first option -- it feels like a better solution to the specific problem here.
Would be good to get your thoughts and perhaps some pointers towards intercepting the processing of TypeAlias
into a custom node (if that's a sensible approach/I'm thinking about that right).
from jedi.
Sorry for the large delay, I kind of forgot about this tab and got sick after. I'm generally fine with both options. I think both options are better then the status quo.
The reason why I don't think Option 2 is terrible is that Jedi has never been about absolute precision like Mypy for example, we have always tried to give the user as much as possible, even with sometimes questionable heuristics. This might be another "questionable" heuristic, that is however not completely wrong either when it comes to autocompletion.
from jedi.
Related Issues (20)
- `LazyKnownValues` has no attribute `string_name`? HOT 4
- Enum name auto-completion without parentheses HOT 1
- Jedi searches the python interpreter in the wrong path. HOT 8
- Unhandled Exception with Unnamed Lambdas When Analyzing References Using dynaconf
- Add support for async pytest fixtures
- Is it possible to generate completion for `argparse.Namespace`? HOT 5
- TypedDict : Suggestion issues HOT 2
- Python stubs loaded from extensions folder even when using an explicit interpreter HOT 8
- Error when trying to detect environment HOT 5
- `PathFinder` has no attribute `find_module` in `python 12.2` HOT 2
- Questions about Copilot + Open Source Software Hierarchy HOT 1
- What exactly does "smart_sys_path" do? HOT 5
- Completion fails when variable name is identical to type name HOT 4
- 'TreeInstance' object has no attribute 'with_generics' when using typing.Literal["str"] return annotation on property HOT 4
- How to discover the import statement for a particular Name? HOT 4
- Does Jedi support type inference for type annotations that include generics? HOT 2
- _get_executable_path() can't get the correct path on Windows Anaconda
- Issues with pytest 8 HOT 1
- [Feature request] Support for syntax coloring (based on symbol type) HOT 1
- Script.infer() unexpectedly returns empty list HOT 10
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jedi.